Skip to content

Commit 4556fad

Browse files
committed
πŸ‘‘ G4-1976
1 parent 52ace55 commit 4556fad

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

β€ŽπŸ‘‘ G4/1976.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
n = int(input())
2+
m = int(input())
3+
parent = [i for i in range(n+1)]
4+
5+
def find(x):
6+
if x == parent[x]: return x
7+
parent[x] = find(parent[x])
8+
return parent[x]
9+
10+
def union(x, y):
11+
x = find(x)
12+
y = find(y)
13+
if x != y:
14+
parent[x] = y
15+
16+
for i in range(n):
17+
temp = list(map(int, input().split()))
18+
for j in range(n):
19+
if temp[j] == 1:
20+
union(i+1, j+1)
21+
22+
path = list(map(int, input().split()))
23+
24+
for i in range(m-1):
25+
if find(path[i]) != find(path[i+1]):
26+
print("NO")
27+
break
28+
else:
29+
print("YES")

0 commit comments

Comments
Β (0)