forked from tony9402/baekjoon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (29 loc) · 983 Bytes
/
main.py
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
33
34
35
# Authored by : yj2221
# Co-authored by : tony9402
# Link : http://boj.kr/b4c107ca25f442e8bef9f8486e248741
import sys
import heapq
def input():
return sys.stdin.readline().rstrip()
INF = 99999999
def dijkstra(start, dependency):
pq = [[0,start]]
result = [INF for _ in range(n+1)]
result[start] = 0
while pq:
cur_time, cur = heapq.heappop(pq)
for next_com, next_time in dependency[cur].items():
time = cur_time + next_time
if result[next_com] > time:
result[next_com] = time
heapq.heappush(pq, [time, next_com])
return result
for testcase in range(int(input())):
n, d, c = map(int,input().split())
dependency = {i:{} for i in range(1,n+1)}
for _ in range(d):
a, b, s = map(int,input().split())
dependency[b][a] = s
result = dijkstra(c, dependency)
result = [value for value in result if value != INF]
print(len(result), max(result))