3040: 最短路(road)

來源:互聯網
上載者:User

題目連結

題目大意:求點1到點N的最短路

題解:用pbds裡的堆最佳化……

我的收穫:get姿勢

#include<iostream>#include<cstdio>#include<cstring>#include<ext/pb_ds/priority_queue.hpp>#define ll long long#define pa pair<ll,int>#define llinf 9000000000000000000LLusing namespace std;using namespace __gnu_pbds;typedef __gnu_pbds::priority_queue<pa,greater<pa>,pairing_heap_tag > heap;int n,m,cnt,last[1000005];int T,rxa,rxc,rya,ryc,rp;heap::point_iterator id[1000005];int x,y,z;ll dis[1000005];struct data{int to,next,v;}e[10000005];inline 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;}void insert(int u,int v,int w){    e[++cnt].to=v;e[cnt].next=last[u];last[u]=cnt;e[cnt].v=w;}void dijkstra(){    heap q;    for(int i=1;i<=n;i++)dis[i]=llinf;    dis[1]=0;id[1]=q.push(make_pair(0,1));    while(!q.empty())    {        int now=q.top().second;q.pop();        for(int i=last[now];i;i=e[i].next)            if(e[i].v+dis[now]<dis[e[i].to])            {                dis[e[i].to]=e[i].v+dis[now];                if(id[e[i].to]!=0)                    q.modify(id[e[i].to],make_pair(dis[e[i].to],e[i].to));                else id[e[i].to]=q.push(make_pair(dis[e[i].to],e[i].to));            }    }}int main(){    n=read();m=read();    T=read();rxa=read();rxc=read();rya=read();ryc=read();rp=read();    int a,b;    for(int i=1;i<=T;i++)    {        x=((ll)x*rxa+rxc)%rp;        y=((ll)y*rya+ryc)%rp;        a=min(x%n+1,y%n+1);        b=max(y%n+1,y%n+1);        insert(a,b,100000000-100*a);    }    for(int i=1;i<=m-T;i++)    {        x=read(),y=read(),z=read();        insert(x,y,z);    }    dijkstra();    printf("%lld",dis[n]);    return 0;}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.