intvv=tt.second; intsumc=c+cc; if(sumc<disf[vv]){ intt=disf[vv]; disf[vv]=sumc; sumc=t; pq.push(make_pair(disf[vv],vv)); } if(sumc>disf[vv]&&sumc<diss[vv]){ diss[vv]=sumc; pq.push(make_pair(diss[vv],vv)); } } } cout<<diss[n]<<endl; return0; }...
这道问题是求1-N的次短路的长度,我们直接在dist[maxn][2]上加1维更新即可, 代码如下: #include <cstdio>#include<cstring>#include<algorithm>#include<vector>#include<queue>usingnamespacestd;constintmaxn =5000+10;intN, R;structedge {intv, c; }; vector<edge>G[maxn];structDij {intu, flog...
思路 这是严格次短路。(题目数据有点水。。。) 到某个顶点v的次短路要么是其他某个顶点u的最短路再加上e(u,v),要么是到u的次短路再加上e(u,v)的边。因此对于每个顶点,我们记录的不仅仅的最短距离,还有次短距离。 考虑在什么情况下会更新最短路。(可重复走同一条边) 1、由父亲节点过来的距离小于最短...
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.
nxt[++tot]=fst[b],fst[b]=tot,go[tot]=a,val[tot]=c; } inlinevoidgetans(){ memset(dis,inf,sizeof(dis));memset(sedis,inf,sizeof(sedis)); dis[1]=0;que.push(make_pair(0,1));while(!que.empty()){intu=que.top().second,d=que.top().first;d=-d;que.pop();//注意这里的d...
#include<iostream>#include<cstdio>#include<algorithm>usingnamespacestd;constintN =10;constintM =10;constintINF =0x3f3f3f3f;intd[N][N];intn;voidinput(){for(inti =0; i < N; i ++)fill(d[i], d[i]+N, INF);intm; cin >> m; ...
1 // File Name: 3255.cpp 2 // Author: Missa 3 // Created Time: 2013/4/5 星期五 1:01:09 4 5 #include<iostream> 6 #include<cstdio> 7 #include<cstring> 8 #include<algorithm> 9 #include<cmath> 10 #include<queue> 11 #include<stack> 12 #include<string> 13 #include<vector> 14...