We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 037e7cd commit d2ca98aCopy full SHA for d2ca98a
YoonYn9915/Graph/2025-03-08-[백준]-#1976-여행가자.py
@@ -0,0 +1,29 @@
1
+import sys
2
+
3
+input = sys.stdin.readline
4
+n = int(input())
5
+m = int(input())
6
+network = []
7
+visited = [0 for _ in range(n)]
8
+for _ in range(n):
9
+ network.append(list(map(int, input().split())))
10
+lst = list(map(int, input().split()))
11
12
13
+def dfs(start):
14
+ visited[start] = 1
15
+ for index, j in enumerate(network[start]):
16
+ if j == 1 and visited[index] == 0:
17
+ visited[index] = 1
18
+ dfs(index)
19
20
21
+dfs(lst[0] - 1)
22
+if 0 not in visited:
23
+ print('YES')
24
+ exit()
25
+for i in lst:
26
+ if visited[i - 1] == 0:
27
+ print('NO')
28
29
+print('YES')
0 commit comments