[๋ฐฑ์ค-6118] ์จ๋ฐ๊ผญ์ง / Python
๐ Problem Solving/Baekjoon
6118๋ฒ: ์จ๋ฐ๊ผญ์ง
์ฌ์๊ธฐ๋ ์ํ๋์ ๊ต์ธ ๋์ฅ์์ ์จ๋ฐ๊ผญ์ง์ ํ๊ณ ์๋ค. ๋์ฅ์๋ ํ๊ฐ์ด ๋ง์ด ๋๋ ค์๊ณ ์ฌ์๊ธฐ๋ ๊ทธ ์ค์ ํ๋์ ์จ์ด์ผ ํ๋ค. ํ๊ฐ์ ๊ฐ์๋ N(2 <= N <= 20,000)๊ฐ์ด๋ฉฐ, 1 ๋ถํฐ ์๋ค๊ณ ํ์. ์ฌ
www.acmicpc.net
import sys
import heapq
input = sys.stdin.readline
INF = int(1e9)
n, m = map(int, input().split())
graph = [[] for _ in range(n + 1)]
distance = [-1] * (n + 1)
def dijkstra(start):
q = []
heapq.heappush(q, (0, start))
distance[start] = 0
while q:
dist, now = heapq.heappop(q)
for i in graph[now]:
if distance[i] == -1:
distance[i] = dist + 1
heapq.heappush(q, (distance[i], i))
for _ in range(m):
a, b = map(int, input().split())
graph[a].append(b)
graph[b].append(a)
dijkstra(1)
print(distance.index(max(distance)), max(distance), distance.count(max(distance)))
ํด์ค
๋ค์ต์คํธ๋ผ๋ก ํด๊ฒฐํ๋ค. ์ด๋ ต์ง ์์ ๋ฌธ์ ์๋๋ฐ ์์ ์ ์ ์ 1๋ก ์ค์ ์ ํด์ 100% ํ๋ ธ์ต๋๋ค๊ฐ ๋ด๋ค..๐ ์์ ์ ์ ์ 0์ผ๋ก ์ค์ ํด์ค์ผ ํ๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-5972] ํ๋ฐฐ ๋ฐฐ์ก / Python (0) | 2021.07.02 |
---|---|
[๋ฐฑ์ค-18405] ๊ฒฝ์์ ์ ์ผ / Python (0) | 2021.07.02 |
[๋ฐฑ์ค-1743] ์์๋ฌผ ํผํ๊ธฐ / Python (0) | 2021.07.02 |
[๋ฐฑ์ค-1926] ๊ทธ๋ฆผ / Python (0) | 2021.07.01 |
[๋ฐฑ์ค-2251] ๋ฌผํต / Python (0) | 2021.07.01 |