#include<iostream>
#include<cstring>
using namespace std;
int t,n,m,d[2005],tot=0;
struct ed{
int u,v,w;
} edge[70005];
bool bellman_Ford(int v0){
memset(d,0x3f,sizeof(d));
d[v0]=0;
for(int i=1;i<n;++i)
for(int j=1;j<=tot;++j)
if(d[edge[j].u]+edge[j].w<d[edge[j].v]) d[edge[j].v]=d[edge[j].u]+edge[j].w;
for(int j=1;j<=tot;++j) if(d[edge[j].u]+edge[j].w<d[edge[j].v]) return false;
return true;
}
int main(){
cin>>t;
while(t--){
cin>>n>>m;
int x,y,z;
for(int i=1;i<=m;++i){
cin>>x>>y>>z;
edge[++tot].u=x;
edge[tot].v=y;
edge[tot].w=z;
if(z>=0){
edge[++tot].u=y;
edge[tot].v=x;
edge[tot].w=z;
}
}
if(bellman_Ford(1)) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
}
return 0;
}
求助,只对了2个点