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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【POJ】3255 Roadblocks(次短路+spfa)

發布時間:2025/3/17 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【POJ】3255 Roadblocks(次短路+spfa) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

http://poj.org/problem?id=3255

同匈牙利游戲。

但是我發現了一個致命bug。

就是在匈牙利那篇,應該dis2單獨if,而不是else if,因為dis2和dis1相對獨立。有可能在前邊兩個if改了后還有更優的次短路。

所以,,wikioi那題太水,讓我水過了。。

#include <cstdio> #include <cstring> #include <cmath> #include <string> #include <iostream> #include <algorithm> using namespace std; #define rep(i, n) for(int i=0; i<(n); ++i) #define for1(i,a,n) for(int i=(a);i<=(n);++i) #define for2(i,a,n) for(int i=(a);i<(n);++i) #define for3(i,a,n) for(int i=(a);i>=(n);--i) #define for4(i,a,n) for(int i=(a);i>(n);--i) #define CC(i,a) memset(i,a,sizeof(i)) #define read(a) a=getint() #define print(a) printf("%d", a) #define dbg(x) cout << #x << " = " << x << endl #define printarr(a, n, m) rep(aaa, n) { rep(bbb, m) cout << a[aaa][bbb]; cout << endl; } inline const int getint() { int r=0, k=1; char c=getchar(); for(; c<'0'||c>'9'; c=getchar()) if(c=='-') k=-1; for(; c>='0'&&c<='9'; c=getchar()) r=r*10+c-'0'; return k*r; } inline const int max(const int &a, const int &b) { return a>b?a:b; } inline const int min(const int &a, const int &b) { return a<b?a:b; }const int N=5050; const long long oo=~0ull>>2; int m, n, vis[N], q[N], front, tail, ihead[N], cnt; long long d[N], d2[N]; struct ED { int to, next; long long w; }e[200010]; inline void add(const int &u, const int &v, const int &w) {e[++cnt].next=ihead[u]; ihead[u]=cnt; e[cnt].to=v; e[cnt].w=w; } long long spfa(const int &s, const int &t) {for1(i, 0, t) d[i]=d2[i]=oo;d[s]=front=tail=0; vis[s]=1; q[tail++]=s;int u, v, w;while(front!=tail) {u=q[front++]; if(front==N) front=0; vis[u]=0;for(int i=ihead[u]; i; i=e[i].next) {v=e[i].to; w=e[i].w;if(d[v]>d[u]+w) {d2[v]=d[v]; d[v]=d[u]+w;if(!vis[v]) { vis[v]=1; q[tail++]=v; if(tail==N) tail=0; }}else if(d2[v]>d[u]+w && d[v]<d[u]+w) {d2[v]=d[u]+w;if(!vis[v]) { vis[v]=1; q[tail++]=v; if(tail==N) tail=0; }}if(d2[v]>d2[u]+w) {d2[v]=d2[u]+w;if(!vis[v]) { vis[v]=1; q[tail++]=v; if(tail==N) tail=0; }}}}if(d2[t]!=oo) return d2[t];return -1; }int main() {read(n); read(m);int x, y, z;rep(i, m) {read(x); read(y); read(z);add(x, y, z); add(y, x, z);}printf("%lld", spfa(1, n));return 0; }

?

?


?

?

Description

Bessie has moved to a small farm and sometimes enjoys returning to visit one of her best friends. She does not want to get to her old home too quickly, because she likes the scenery along the way. She has decided to take the second-shortest rather than the shortest path. She knows there must be some second-shortest path.

The countryside consists of R (1 ≤ R ≤ 100,000) bidirectional roads, each linking two of the N (1 ≤ N ≤ 5000) intersections, conveniently numbered 1..N. Bessie starts at intersection 1, and her friend (the destination) is at intersection N.

The second-shortest path may share roads with any of the shortest paths, and it may backtrack i.e., use the same road or intersection more than once. The second-shortest path is the shortest path whose length is longer than the shortest path(s) (i.e., if two or more shortest paths exist, the second-shortest path is the one whose length is longer than those but no longer than any other path).

Input

Line 1: Two space-separated integers: N and R
Lines 2..R+1: Each line contains three space-separated integers: A, B, and D that describe a road that connects intersections A and B and has length D (1 ≤ D ≤ 5000)

Output

Line 1: The length of the second shortest path between node 1 and node N

Sample Input

4 4 1 2 100 2 4 200 2 3 250 3 4 100

Sample Output

450

Hint

Two routes: 1 -> 2 -> 4 (length 100+200=300) and 1 -> 2 -> 3 -> 4 (length 100+250+100=450)

Source

USACO 2006 November Gold

總結

以上是生活随笔為你收集整理的【POJ】3255 Roadblocks(次短路+spfa)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

主站蜘蛛池模板: 日本高清视频一区二区 | 亚洲色图丝袜美腿 | 欧美日韩国产综合网 | 日日摸夜夜 | 久久女人 | 什么网站可以看毛片 | 亚洲国产网址 | 理论片大全免费理伦片 | 99re这里只有| 国产偷人妻精品一区 | 永久免费视频网站直接看 | 亚洲精品视频二区 | 日韩成人自拍 | 熟妇高潮一区二区三区 | www.brazzers.com| 久久成年人 | jizz自拍| 丁香在线视频 | 4438全国最大成人网 | 久久欲| www.天天干.com| 午夜视频1000 | 日韩美女福利视频 | 国产欧美综合在线 | 婷婷五月综合激情 | jizz日本18| 国产免费黄色片 | 极品粉嫩小仙女高潮喷水久久 | 亚洲福利在线观看 | 国产又粗又猛又爽又黄91 | 一久久 | 亚洲一区和二区 | 欧美激情一级 | 国产精品乱码一区 | 久草视频免费在线 | 四虎看黄 | 白丝校花扒腿让我c | 天天色网站| 毛片亚洲av无码精品国产午夜 | 玖玖爱精品| 波多野结衣在线观看一区二区 | 99riav国产精品视频 | 中国人与拘一级毛片 | 青娱乐最新地址 | 又紧又大又爽精品一区二区 | 午夜精品福利一区二区 | 女人下边被添全过视频 | 亚洲福利精品视频 | 日韩三级麻豆 | 成人动漫av在线 | 日韩亚洲欧美中文字幕 | 在线免费观看日韩视频 | 国产精品自拍网站 | 日韩免费av在线 | 国产麻豆一精品一男同 | 色乱码一区二区三在线看 | 手机在线毛片 | 免费无码不卡视频在线观看 | 殴美一级黄色片 | 69久久 | 成a人v| 超碰97免费在线 | 蜜桃av一区二区 | a天堂资源在线观看 | 亚洲视频欧美视频 | 欧美一级黄色片视频 | 麻豆视频在线观看 | 国产精品18久久久久久无码 | av不卡中文字幕 | 欧美hdxxxx| 蜜臀av性久久久久蜜臀aⅴ涩爱 | 97国产 | 久久久国产网站 | 日韩在线二区 | 国产视频精选 | 久久综合久色欧美综合狠狠 | 91av官网 | 日韩av在线看免费观看 | 少妇高潮av | 欧美精品一区二区三区四区五区 | 五十路息子 | 国产精品一区二区三区在线免费观看 | 黑料视频在线观看 | 午夜久久久精品 | 熟女一区二区三区四区 | 色呦呦网站 | 亚洲制服丝袜在线播放 | 亚洲性生活网站 | av美女在线 | 成全影视在线观看第8季 | 日日噜噜噜夜夜爽爽狠狠 | 色噜噜狠狠狠综合曰曰曰 | 好爽…又高潮了毛片免费看 | 777色婷婷 | 恶虐女帝安卓汉化版最新版本 | 欧州一区二区三区 | 日本一本一道 | 91av影院| 日韩欧美中文一区 |