int input for in range append list map int input split while len len f

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
n = int(input())
A = []
B = [0]
for i in range(n):
A.append(list(map(int, input().split())))
while len(B)!=n:
m = len(B)
for i in range(n):
for j in B:
if A[j][i]==1:
B.append(i)
B = list(set(B))
if len(B)==m:
break
if len(B)==n:
print ("YES")
else:
print ("NO")