标签:print std def argv color scanf oid ret tor
#include <cstdio> #include <queue> #define N 15000005 using namespace std; bool vis[N/10]; int n,m,T,rxa,rxc,rya,ryc,rp,cnt,to[N<<1],head[N],nextt[N<<1],val[N<<1]; long long far[N/10]; inline int min(int a,int b) {return a>b?b:a;} inline int max(int a,int b) {return a>b?a:b;} inline void ins(int u,int v,int w) { nextt[++cnt]=head[u];to[cnt]=v;val[cnt]=w; head[u]=cnt; } struct node { int x,y; bool operator<(node a)const { return y>a.y; } }; priority_queue<node>q; int dijkstra() { for(int i=1;i<=n;++i) vis[i]=false,far[i]=1e18; far[1]=0; q.push((node){1,far[1]}); for(node now;!q.empty();) { now=q.top(); q.pop(); if(vis[now.x]) continue; vis[now.x]=true; for(int i=head[now.x];i;i=nextt[i]) { int v=to[i]; if(far[v]>far[now.x]+val[i]) { far[v]=far[now.x]+val[i]; if(!vis[v]) q.push((node){v,far[v]}); } } } return far[n]; } int main(int argc,char *argv[]) { scanf("%d%d",&n,&m); int x=0,y=0,z=0; scanf("%d%d%d%d%d%d",&T,&rxa,&rxc,&rya,&ryc,&rp); for(int i=1;i<=T;++i) { x=((long long)x*rxa+rxc)%rp; y=((long long)x*rya+ryc)%rp; int a=min(x%n+1,y%n+1),b=max(y%n+1,y%n+1); ins(a,b,100000000-100*a); } for(int u,v,w;m--;) { scanf("%d%d%d",&u,&v,&w); ins(u,v,w); } printf("%lld\n",dijkstra()); return 0; }
标签:print std def argv color scanf oid ret tor
原文地址:http://www.cnblogs.com/ruojisun/p/7701876.html