We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d5e373a commit 0f62c9fCopy full SHA for 0f62c9f
1 file changed
live10/test101/문제3/백한결.py
@@ -0,0 +1,24 @@
1
+from collections import deque
2
+
3
+def solution(n, edge):
4
+ graph = [[] for _ in range(n + 1)]
5
6
+ for a, b in edge:
7
+ graph[a].append(b)
8
+ graph[b].append(a)
9
10
+ distance = [-1] * (n + 1)
11
+ distance[1] = 0
12
13
+ queue = deque([1])
14
15
+ while queue:
16
+ now = queue.popleft()
17
+ for neighbor in graph[now]:
18
+ if distance[neighbor] == -1:
19
+ distance[neighbor] = distance[now] + 1
20
+ queue.append(neighbor)
21
22
+ max_distance = max(distance)
23
24
+ return distance.count(max_distance)
0 commit comments