Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dfs(s):
- used[s] = 1
- que.append(s)
- while len(que) != 0:
- v = que[0]
- que.remove(v)
- y = True
- k = 0
- if v not in com2 and v not in com1:
- com1.append(v)
- elif v in com2:
- y = False
- for i in g[v]:
- if not used[i]:
- if y:
- com2.append(i)
- else:
- com1.append(i)
- used[i] = 1
- que.append(i)
- n = int(input())
- g = dict()
- for i in range(n):
- mas = [int(x) for x in input().split()]
- for j in mas:
- if j != 0:
- if i + 1 not in g:
- g[i + 1] = set()
- if j not in g:
- g[j] = set()
- g[i + 1].add(j)
- g[j].add(i + 1)
- used = [0] * (n + 1)
- que = []
- maxk = -1
- com1 = []
- com2 = []
- for i in range(1, n + 1):
- if not used[i]:
- dfs(i)
- print(len(com1))
- print(*com1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement