Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- sys.setrecursionlimit(0x10000000)
- def add(a, b):
- g[a].append(b)
- g[b].append(a)
- def dfs(v, p):
- ans = False
- color[v] = 1
- path.append(v)
- for i in g[v]:
- if color[i] == -1:
- if dfs(i, v):
- ans = True
- elif color[i] == 1 and i != p:
- ans = True
- path.append(i)
- color[v] = 2
- return ans
- n = int(input())
- path = []
- g = []
- color = []
- for i in range(n):
- g.append([])
- color.append(-1)
- for i in range(n):
- l = list(map(int, input().split()))
- for j in range(i + 1, n):
- if (l[j] == 1):
- add(i, j)
- ans = True
- for i in range(n):
- if color[i] == -1:
- ans &= dfs(i, 1)
- if ans:
- print("YES")
- else:
- print("NO")
- print(path)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement