POJ3255(spfa變形,很好的一道題)

2021-07-24 21:00:24 字數 757 閱讀 3488

題意:類似於次最短路,但卻不是次最短路。此題要求的是比最短路大一點的路,意味著在從1到n的過程中奪走了一條邊,我們現在求出多走一條邊的最短路。

思路:既然是多走了一條邊,那麼遍歷每一條邊記錄最小的值。題目保證一定存在這條邊。

#include#include#include#includeusing namespace std;

const int inf = 0x3f3f3f3f;

const int nmax = 5005;

const int mmax = 100005;

class node

edge[mmax*2];

int n,m;

int dis1[nmax],dis2[nmax];

int visit[nmax];

int head[nmax],pos;

void spfa(int s,int dist)

queueq;

q.push(s);

visit[s] = true;

dist[s] = 0;

while(!q.empty())}}

}int main()

spfa(1,dis1);

spfa(n,dis2);

int ans = inf;

for(int i = 1;i <= n; i++)

}printf("%d\n",ans);

return 0;

}

很好的一道面試題

批量註冊使用者,每次 100個。註冊新使用者,要求使用者名稱與email不能與以前的重複。mysqli new mysqli host,user,pass for i 0 i i 基礎 應該把count提到迴圈外。基礎 在字串中拼裝陣列時候應該用 括起來。基礎 re 1 re 2應該是 re 1 r...

poj1019 很好的一道數學題 思路挺巧

借鑑別人的思路,利用位數求解 思路不錯。題意 求第n位的數字。函式log10 double i 1,求的是乙個數的位數。當達到31270時,已經超過了2147483647位數 include include include define max 31270 using namespace std u...

poj 3087(一道簡單的模擬)

題目是乙個很明顯的模擬,兩個等長字串交錯合併,並更新兩個字串為合併後字串的前後兩個部分,求合併成給定字串的最少次數。模擬合併的過程就可以了,唯一需要注意的就是如果不能合成指定字串會形成乙個迴圈。include include includeusing namespace std const int ...