diff --git a/POJ/3255.cpp b/POJ/3255.cpp new file mode 100644 index 0000000..ce4b902 --- /dev/null +++ b/POJ/3255.cpp @@ -0,0 +1,101 @@ +#include +#include +#include + +#include +#include +#include +#include +#include + +#include +using namespace std; + +#define INF 1e9+7 + +#define MAXN 5000 +#define MAXR 100000 + +int N,R; + +struct edge +{ + edge(int To,int Dist):to(To),dist(Dist){} + + int to; + int dist; +}; + +vector G[MAXN+1]; + +/// 最短路: dis[i]=从1号路口出发到i路口的最短距离 +int dis[MAXN+1]; +/// 次短路: second_dis[i]=从1号路口出发到i路口的次短距离 +int second_dis[MAXN+1]; + +/// PR.first 为距离, PR.second 为点 +typedef pair PR; + +void solve() +{ + priority_queue< PR,vector,greater > bus; + fill(dis,dis+N,INF); + fill(second_dis,second_dis+N,INF); + + dis[0]=0; + bus.push(PR(0,0)); + + while(!bus.empty()) + { + PR p=bus.top(); + bus.pop(); + + int d=p.first; + int v=p.second; + + if(second_dis[v]dd) + { + /// 如果最短路比新合成距离长,交换(?) + swap(dis[e.to],dd); + bus.push(PR(dis[e.to],e.to)); + } + + /// 现在一定有: dd>dis[e.to] + + if(second_dis[e.to] > dd && dis[e.to] < dd) + { + second_dis[e.to]=dd; + bus.push(PR(second_dis[e.to],e.to)); + } + } + } + + printf("%d\n",second_dis[N-1]); +} + +int main() +{ + scanf("%d %d",&N,&R); + for(int i=0;i