大水题
code:
#include<iostream>
#include<cstdio>
#include<queue>
#include<algorithm>
#include<cstring>
using namespace std;
#define maxn 3005
int head[maxn],cnt,n,m,w,vis[maxn],num[maxn],dis[maxn];
struct node{int to;int from;int w;
}edge[maxn*2];
void add(int u,int v,int w)
{cnt++;edge[cnt].to = v;edge[cnt].from = head[u];edge[cnt].w = w;head[u] = cnt;
}bool spfa()
{queue<int>q;vis[1] = 1;q.push(1);num[1] = 1;dis[1] = 0;while(!q.empty()){int x = q.front();q.pop();vis[x] = 0;for(int i=head[x];i;i=edge[i].from){int to = edge[i].to;if(dis[to]>dis[x]+edge[i].w){dis[to] = dis[x]+edge[i].w;if(!vis[to]){vis[to] = 1;q.push(to);num[to]++;}}if(num[to]>=n)return 1;}}return 0;
}
int main()
{int t;cin>>t;while(t--){memset(head,0,sizeof head);memset(edge,0,sizeof edge);memset(vis,0,sizeof vis);memset(dis,0x3f,sizeof dis);memset(num,0,sizeof num);cnt = 0;cin>>n>>m>>w;for(int i=1;i<=m;i++){int u,v,p;scanf("%d%d%d",&u,&v,&p);add(u,v,p);add(v,u,p);}for(int i=1;i<=w;i++){int u,v,p;scanf("%d%d%d",&u,&v,&p);add(u,v,-1*p);
// add(v,u,-1*p); }if(spfa())printf("YES\n");else printf("NO\n");}
}