BZOJ3040:最短路——题解
https://www.lydsy.com/JudgeOnline/problem.php?id=3040
题意rt,使用pb_ds的堆解决本问题。
所以其实就是mark一下的。
不过有人确认过官方不能使用“using namespace __gnu_pbds;”
#include<cmath> #include<queue> #include<cstdio> #include<cctype> #include<cstring> #include<iostream> #include<algorithm> #include<ext/pb_ds/priority_queue.hpp> using namespace std; typedef long long ll; typedef pair<ll,int>pii; typedef __gnu_pbds::priority_queue<pii,greater<pii>,__gnu_pbds::pairing_heap_tag> heap; #define fi first #define se second const int N=1e6+5; const int M=1e7+5; const ll INF=1e18; inline int read(){ int X=0,w=0;char ch=0; while(!isdigit(ch)){w|=ch=='-';ch=getchar();} while(isdigit(ch))X=(X<<3)+(X<<1)+(ch^48),ch=getchar(); return w?-X:X; } struct node{ int to,nxt; ll w; }e[M]; int n,m,c,cnt,head[N]; heap q; heap::point_iterator id[N]; inline void add(int u,int v,ll w){ e[++cnt].to=v;e[cnt].w=w;e[cnt].nxt=head[u];head[u]=cnt; } ll dis[N]; void dij(int s){ for(int i=1;i<=n;i++)dis[i]=INF; dis[s]=0;id[s]=q.push(pii(0,s)); while(!q.empty()){ int u=q.top().se;q.pop(); for(int i=head[u];i;i=e[i].nxt){ int v=e[i].to;ll w=e[i].w; if(dis[v]>dis[u]+w){ dis[v]=dis[u]+w; if(id[v]!=0)q.modify(id[v],pii(dis[v],v)); else id[v]=q.push(pii(dis[v],v)); } } } return; } int main(){ n=read(),m=read(); int t=read(),rxa=read(),rxc=read(),rya=read(),ryc=read(),rp=read(); int x=0,y=0; for(int i=1;i<=t;i++){ x=((ll)x*rxa+rxc)%rp; y=((ll)y*rya+ryc)%rp; int u=min(x%n+1,y%n+1),v=max(y%n+1,y%n+1); add(u,v,100000000-100*u); } for(int i=t+1;i<=m;i++){ int u=read(),v=read(),w=read(); add(u,v,w); } dij(1); printf("%lld\n",dis[n]); return 0; }
+++++++++++++++++++++++++++++++++++++++++++
+本文作者:luyouqi233。 +
+欢迎访问我的博客:http://www.cnblogs.com/luyouqi233/+
+++++++++++++++++++++++++++++++++++++++++++