配对堆优化最短路。。。
代码:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<ext/pb_ds/priority_queue.hpp>
#define ll long long
#define pa pair<ll ,int >
using namespace std;
using namespace __gnu_pbds;
typedef __gnu_pbds::priority_queue<pa,greater<pa>,pairing_heap_tag> heap;
const int maxn=1000010;
const ll inf=100000000000000000;
int n,m;
heap q;
heap::point_iterator id[maxn];
ll dist[maxn];
int read()
{
int x=0,f=1;
char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
return x*f;
}
struct edge
{
int t,w;
edge *next;
}*con[maxn];
void ins(int x,int y,int w)
{
//cout<<x<<' '<<y<<' '<<w<<endl;
edge *p=new edge;
p->t=y;
p->w=w;
p->next=con[x];
con[x]=p;
}
void dijkstra()
{
for(int i=2;i<=n;i++) dist[i]=inf;
dist[1]=0;id[1]=q.push(make_pair(0,1));
while(!q.empty())
{
int v=q.top().second;q.pop();
for(edge *p=con[v];p;p=p->next)
if(dist[p->t]>dist[v]+p->w)
{
dist[p->t]=dist[v]+p->w;
if(id[p->t]!=0) q.modify(id[p->t],make_pair(dist[p->t],p->t));
else id[p->t]=q.push(make_pair(dist[p->t],p->t));
}
}
}
int main()
{
n=read();m=read();
int T=read(),a,b,rxa=read(),rxc=read(),rya=read(),ryc=read(),rp=read();
ll x=0,y=0;
m-=T;
while(T--)
{
x=(x*rxa+rxc)%rp;
y=(y*rya+ryc)%rp;
a=min(x%n+1,y%n+1);
b=max(y%n+1,y%n+1);
ins(a,b,100000000-a*100);
}
for(int i=1;i<=m;i++)
{
int cx=read(),cy=read(),cz=read();
ins(cx,cy,cz);
}
dijkstra();
printf("%lld",dist[n]);
return 0;
}