Skip to content

Commit d2ca98a

Browse files
YoonYn9915Mingguriguri
authored andcommitted
[BOJ] 여행가자 / 골드 4 / 60분 실패
https://www.acmicpc.net/problem/1976
1 parent 037e7cd commit d2ca98a

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
exit()
29+
print('YES')

0 commit comments

Comments
 (0)