We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 5cc4eb2 commit 704cbc0Copy full SHA for 704cbc0
1 file changed
live10/test101/문제3/박희경.py
@@ -1,25 +1,24 @@
1
from collections import *
2
3
def solution(n, edge):
4
- answer = 0
5
6
graph = [[] for _ in range(n + 1)]
7
8
for a, b in edge:
9
graph[a].append(b)
10
graph[b].append(a)
11
+ visited = [0] * (n + 1)
12
+ visited[1] = 1
13
14
def bfs(x):
15
q = deque([x])
16
while q:
17
x = q.popleft()
- print(graph[x])
18
for nei in graph[x]:
19
- if nei != 0:
20
- nei = 0
21
- answer += 1
+ if not visited[nei]:
+ visited[nei] = visited[x] + 1
22
q.append(nei)
23
bfs(1)
24
25
- return answer
+ return visited.count(max(visited))
0 commit comments