-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1865.py
More file actions
31 lines (30 loc) · 809 Bytes
/
1865.py
File metadata and controls
31 lines (30 loc) · 809 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
import collections
import sys
tc = int(input())
answer = []
for _ in range(tc):
n, m, w = map(int,sys.stdin.readline().split())
edges = []
inf_cycle = True
dist = [500000]*(n+1)
dist[1] = 0
for _ in range(m):
s, e, t = map(int, sys.stdin.readline().split())
edges.append([s, e, t])
edges.append([e, s, t])
for _ in range(w):
s, e, t =map(int,sys.stdin.readline().split())
edges.append([s,e,t*-1])
for i in range(n):
for s,e,t in edges:
if dist[e] > dist[s] + t:
if i == n-1:
inf_cycle=False
break
dist[e] = dist[s] +t
if inf_cycle ==False:
answer.append('YES')
else:
answer.append('NO')
for ele in answer:
print(ele)