Skip to content

Commit 704cbc0

Browse files
committed
101차 3번 문제 다시 풀이
1 parent 5cc4eb2 commit 704cbc0

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,24 @@
11
from collections import *
22

33
def solution(n, edge):
4-
answer = 0
54

65
graph = [[] for _ in range(n + 1)]
76

87
for a, b in edge:
98
graph[a].append(b)
109
graph[b].append(a)
1110

11+
visited = [0] * (n + 1)
12+
visited[1] = 1
1213

1314
def bfs(x):
1415
q = deque([x])
1516
while q:
1617
x = q.popleft()
17-
print(graph[x])
1818
for nei in graph[x]:
19-
if nei != 0:
20-
nei = 0
21-
answer += 1
19+
if not visited[nei]:
20+
visited[nei] = visited[x] + 1
2221
q.append(nei)
2322
bfs(1)
2423

25-
return answer
24+
return visited.count(max(visited))

0 commit comments

Comments
 (0)