80分求调!!WA#2,#8,#10
查看原帖
80分求调!!WA#2,#8,#10
1028281
czxczx2010楼主2024/8/15 14:22
#include<bits/stdc++.h>
using namespace std;
const int N=1e3+5;
int head[2*N],ver[6*N],edge[6*N],next1[6*N];
int d1,m,c,f,s,tot=0,flag=0;
int cnt[2*N],d[2*N],v[2*N];
queue< int >q;
void spfa(){
	d[s]=d1;v[s]=1;
	q.push(s);
	while(q.size()){
		int x=q.front(); 
		q.pop();
		v[x]=0;
		for(int i=head[x];i;i=next1[i]){
			int y=ver[i],z=edge[i];
			if(d[x]+z>d[y]){
				d[y]=d[x]+z;
				cnt[y]=cnt[x]+1;
				if(cnt[y]>c){
					flag=1;
					return;
				}
				if(v[y]==0){
				    q.push(y);
				    v[y]=1;
			    }
			} 
		}
	}
}
void add(int x,int y,int z){
	ver[++tot]=y;edge[tot]=z;
	next1[tot]=head[x];
	head[x]=tot; 
}
int main(){
	cin>>d1>>m>>c>>f>>s;
	int a,b,c,maxx=-2147483648;
	for(int i=1;i<=m;i++){
		cin>>a>>b;
		add(a,b,d1);
	}
	for(int i=1;i<=f;i++){
		cin>>a>>b>>c;
		add(a,b,d1-c);
	}
	spfa();
	if(flag)cout<<-1;
	else{
		for(int i=1;i<=c;i++){
			maxx=max(maxx,d[i]);
		}
	}
	cout<<maxx;
}
2024/8/15 14:22
加载中...