标签:col stream ons bsp std pos ring const double
#include<cstdio> #include<queue> #include<cstring> #include<cmath> #include<iostream> #define mod 9987 using namespace std; const int N=1000005; int e[N],ne[N],w[N],idx; queue<int> q; int h[1005],po[1005][2],vis[1005],tot=0; double dis[1005]; int n,m; void add(int a,int b,int c) { e[idx]=b; w[idx]=c; ne[idx]=h[a]; h[a]=idx++; } int main() { memset(h,-1,sizeof h); cin>>n>>m; while(m--) { int a,b,c; cin>>a>>b>>c; add(a,b,c); } memset(dis,127,sizeof(dis)); dis[1]=0; vis[1]=1; q.push(1); while(q.size()) { int now=q.front(); q.pop(); vis[now]=0; for(int i=h[now]; ~i; i=ne[i]) { int v=e[i]; if(dis[v]>dis[now]+log(w[i])) { dis[v]=dis[now]+log(w[i]); po[v][0]=now; po[v][1]=w[i]; if(!vis[v]) { vis[v]=1; q.push(v); } } } } int ans=1,pos=n; while(pos!=1) { ans*=po[pos][1]; ans%=mod; pos=po[pos][0]; } printf("%d\n",ans); return 0; }
标签:col stream ons bsp std pos ring const double
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/13041094.html