Skip to content

Commit ba1af42

Browse files
committed
81차 2번 문제 다시 풀이
1 parent 940cabb commit ba1af42

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

live8/test81/문제2/박희경.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
import sys
2+
from collections import *
23

34
input = sys.stdin.readline
45

56
n = int(input())
67
m = int(input())
7-
network = [[] * (n + 1) for _ in range(n + 1)]
8+
network = [[] for _ in range(n + 1)]
89

910
for _ in range(m):
1011
x, y = map(int, input().split())
1112
network[x].append(y)
1213
network[y].append(x)
1314

14-
# [[], [2, 5], [1, 3, 5], [2], [7], [1, 2, 6], [5], [4]]
15+
visited = [0] * (n + 1)
16+
q = deque([1])
17+
while q:
18+
x = q.popleft()
19+
visited[x] = 1
20+
for nx in network[x]:
21+
if not visited[nx]:
22+
visited[nx] = 1
23+
q.append(nx)
24+
25+
print(sum(visited) - 1)
26+
27+
"""
28+
7
29+
6
30+
1 2
31+
2 3
32+
1 5
33+
5 2
34+
5 6
35+
4 7
36+
"""

0 commit comments

Comments
 (0)