日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

BZOJ3040:最短路——题解

發布時間:2023/12/19 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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/+

+++++++++++++++++++++++++++++++++++++++++++

轉載于:https://www.cnblogs.com/luyouqi233/p/9102882.html

總結

以上是生活随笔為你收集整理的BZOJ3040:最短路——题解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。