Link : https://programmers.co.kr/learn/courses/30/lessons/49189
Python
더보기
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
from collections import deque
INF = int(1e9)
def solution(n, edge):
graph = [[] for _ in range(n)]
que = deque()
distance = [INF for _ in range(n)]
visited = [False for _ in range(n)]
for s, e in edge:
s -= 1;
e -= 1
graph[s].append(e)
graph[e].append(s)
que.append((0, 0)) # now_pos, now_stack
while len(que):
s, ns = que.popleft()
if visited[s]:
continue
visited[s] = True
for e in graph[s]:
if ns + 1 > distance[e]:
continue
distance[e] = ns + 1
que.append((e, ns + 1))
distance.pop(0)
max_dist = max(distance)
return distance.count(max_dist)
|
cs |
FeedBack
cjw.git@gmail.com
'알고리즘 > 소스코드' 카테고리의 다른 글
LEETCODE 128. Longest Consecutive Sequence (0) | 2021.08.05 |
---|---|
LEETCODE 46: PERMUTATIONS (0) | 2021.08.05 |
PROGRAMMERS 42861: 섬 연결하기 (0) | 2021.07.18 |
PROGRAMMERS 42842: 카펫 (0) | 2021.07.18 |
PROGRAMMERS 77485: 행렬 테두리 회전하기 (0) | 2021.06.21 |
댓글