// Analyzing ring dist negative initialized to positive infinity @ positive to negative infinity ring #include <the iostream> #include <CString> #include <Queue> #include <algorithm> the using namespace STD; const int N = 1E5, INF = 0x3f3f3f3f ; int dist [N]; int H [N], E [N], NE [N], W [N], IDX; int n-, m, Z; void the Add ( int A, int B, int C) { E [IDX] = B; W [IDX] = C; NE [IDX] = H [A]; H [A]=idx++; } bool st[N]; int times[N]; bool spfa() { memset(st,0,sizeof st); memset(times,0,sizeof times); queue<int>q; st[1]=1; dist[1]=0; q.push(1); times[1]++; while(q.size()) { int t=q.front(); q.pop(); st[t]=0; for(int i=h[t];~i;i=ne[i]) { int j=e[i]; if(dist[j]>dist[t]+w[i]) { dist[j]=dist[t]+w[i]; if(!st[j]) { st[j]=1; q.push(j); times[j]++; if(times[j]>n) return true; } } } } return false; } int main() { int t,a,b,c; cin>>t; while(t--) { cin>>n>>m>>z; idx=0; memset(h,-1,sizeof h); memset(dist,0x3f,sizeof dist); for(int i=1;i<=m;i++) { int a,b,c; cin>>a>>b>>c; add(a,b,c); add(b,a,c); } for(int i=1;i<=z;i++) { int a,b,c; cin>>a>>b>>c; add(a,b,-c); } if(spfa()) cout<<"YES"<<endl; else cout<<"NO"<<endl; } return 0; }