We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 52ace55 commit 4556fadCopy full SHA for 4556fad
βπ G4/1976.py
@@ -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