10282번: 해킹
최흉최악의 해커 yum3이 네트워크 시설의 한 컴퓨터를 해킹했다! 이제 서로에 의존하는 컴퓨터들은 점차 하나둘 전염되기 시작한다. 어떤 컴퓨터 a가 다른 컴퓨터 b에 의존한다면, b가 감염되면
www.acmicpc.net
import sys
import heapq
def dijkstra(N, start):
qu = []
heapq.heappush(qu, (0, start))
dist = [float("inf")] * (N+1)
dist[start] = 0
while qu:
d, node = heapq.heappop(qu)
if d > dist[node]:
continue
for w, e in graph[node]:
nd = d + w
if nd < dist[e]:
dist[e] = nd
heapq.heappush(qu, (nd, e))
return dist
T = int(input())
for _ in range(T):
N, D, C = map(int, input().split())
graph = [[] for _ in range(N+1)]
for _ in range(D):
n1, n2, w = map(int, sys.stdin.readline().split())
graph[n2].append((w, n1))
ans = dijkstra(N, C)
ans = [x for x in ans if x != float("inf")]
print(len(ans), max(ans))
'BOJ 알고리즘 (패캠) > 그래프' 카테고리의 다른 글
1774번: 우주신과의 교감 (그래프, MST, 크루스칼) - Fastcampus (0) | 2020.10.22 |
---|---|
5719번: 거의최단경로 (그래프, 다익스트라) - Fastcampus (0) | 2020.10.22 |
1325번: 효율적인해킹 (그래프, BFS, DFS) - Fastcampus (0) | 2020.10.21 |
1012번: 유기농배추 (그래프, BFS, DFS) - Fastcampus (0) | 2020.10.16 |
2606번: 바이러스 (그래프, BFS, DFS) - Fastcampus (0) | 2020.10.15 |