Skip to content

Instantly share code, notes, and snippets.

@shakayami
Last active July 10, 2021 06:55
Show Gist options
  • Save shakayami/c9b2611cf123c221b2056ee31565a705 to your computer and use it in GitHub Desktop.
Save shakayami/c9b2611cf123c221b2056ee31565a705 to your computer and use it in GitHub Desktop.
N,Q=map(int,input().split())
A=[int(i) for i in input().split()]
G=[[0 for j in range(N)]for i in range(N)]
for _ in range(Q):
x,y=map(int,input().split())
G[x-1][y-1]=1
G[y-1][x-1]=1
S=sum(A)
X=[[] for i in range(S+1)]
isok=False
L=[[i] for i in range(N)]
for k in range(N-1):
for seq in L:
tmp=0
for i in seq:
tmp+=A[i]
X[tmp].append(seq)
if len(X[tmp])>=2:
isok=True
break
if isok:
break
nL=[]
for seq in L:
for i in range(max(seq)+1,N):
isaddable=True
for j in seq:
if G[i][j]==1:
isaddable=False
break
if isaddable:
nL.append(seq+[i])
L=nL
for s in range(S+1):
if len(X[s])>=2:
B=X[s][0]
C=X[s][1]
print(len(B))
print(*[x+1 for x in B])
print(len(C))
print(*[y+1 for y in C])
break
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment