如题。取模我看起来没问题。
#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;
}