拓扑排序 #9 #10 WA 求调
  • 板块P1685 游览
  • 楼主libu2333
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/7/2 17:39
  • 上次更新2025/7/3 12:01:30
查看原帖
拓扑排序 #9 #10 WA 求调
1475943
libu2333楼主2025/7/2 17:39

如题。取模我看起来没问题。

#include<bits/stdc++.h>
using namespace std;
#define int unsigned long long
const int mod=10000;
struct edge{int v,w;};
vector<edge> e[100005];
int d[100005];
int n,m,s,t,t0;
int f1[100005],f2[100005];
void topo(){
	queue<int> q;
	q.push(s);
	f1[s]=1;
	while(!q.empty()){
		int u=q.front();
		q.pop();
		for(auto e:e[u]){
			int v=e.v,w=e.w%mod;
			if(f1[u]){
				f1[v]=(f1[v]+f1[u])%mod;
				f2[v]=(f2[v]+f2[u]+(f1[u]*w)%mod)%mod;
			}
			d[v]--;
			if(d[v]==0)q.push(v);
		}
	}
}
signed main(){
	cin>>n>>m>>s>>t>>t0;
	for(int i=0;i<m;i++){
		int u,v,w;
		cin>>u>>v>>w;
		e[u].push_back({v,w});
		d[v]++;
	}
	topo();
	if(f1[t]==0){
		cout<<0<<endl;
		return 0;
	}
    int ans=(f2[t]+((f1[t]-1)*t0)%mod)%mod;
	cout<<ans<<endl;
	return 0;
}
2025/7/2 17:39
加载中...