[BZOJ3040]最短路

配对堆优化最短路。。。
代码:

#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;

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值