forked from shunr/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdmopc17c1p3.py
More file actions
40 lines (34 loc) · 929 Bytes
/
dmopc17c1p3.py
File metadata and controls
40 lines (34 loc) · 929 Bytes
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
36
37
38
39
40
import sys
from collections import defaultdict
from heapq import *
input = sys.stdin.readline
n, m = (int(i) for i in input().split())
def djik(graph, danger, targ):
global n
q = [(0, 0, 1)]
visited = [0 for i in range(n+1)]
done = False
while q:
succ, splooge, x = heappop(q)
if x == targ:
done = True
print(succ, splooge)
return
visited[x] = 1;
for node in graph[x]:
if visited[node] == 0:
heappush(q, (succ + danger[(x, node)], splooge + 1, node))
print(-1)
danger = defaultdict(lambda: -420)
graph = [[] for i in range(n+1)]
for i in range(m):
a, b, t = (int(i) for i in input().split())
if danger[(a, b)] == -420:
graph[a].append(b)
graph[b].append(a)
danger[(a, b)] = t
danger[(b, a)] = t
if t == 0 and danger[(a, b)] == 1:
danger[(a, b)] = 0
danger[(b, a)] = 0
djik(graph, danger, n)