Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- n = int(input())
- a = []
- for i in range(n):
- a.append(list(map(int,input().split())))
- def loop_exists(v,f):
- visited[v] = 1
- res = False
- for i in range(n):
- if a[v][i]:
- if i != f:
- if visited[i]:
- return True
- res = loop_exists(i,v)
- return res
- def isTree(a):
- global visited
- if len(a) == 1 and a[0][0] == 0:
- return True
- for r in range(n):
- visited = [0]*n
- if sum(a[r]) == 0 or loop_exists(r,-1):
- return False # если есть узлы, не связанные с другими
- return True
- if isTree(a):
- print('YES')
- else:
- print('NO')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement