P3385求助WA
  • 板块题目总版
  • 楼主wlxs2006
  • 当前回复6
  • 已保存回复6
  • 发布时间2020/8/29 15:12
  • 上次更新2023/11/5 14:01:46
查看原帖
P3385求助WA
242405
wlxs2006楼主2020/8/29 15:12
#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个点

2020/8/29 15:12
加载中...