1.题面
http://poj.org/problem?id=1797
2.题意
不想说,心累
3.思路
像dijkstra搞一搞,堆优化
4.代码
/*****************************************************************
> File Name: Cpp_Acm.cpp
> Author: Uncle_Sugar
> Mail: uncle_sugar@qq.com
> Created Time: 2016年07月13日 星期三 14时31分07秒
*****************************************************************/
# include <iostream>
# include <queue>
using namespace std;
const int size = 100000 + 10;
const int INF = INT_MAX>>1;
int n,m;
struct edge{
int to,w;
edge(){}
edge(int _to,int _w):to(_to),w(_w){}
};
struct d{
int w,no;
d(){}
d(int _w,int _no):w(_w),no(_no){};
bool operator < (const d& cmper)const {
return w<cmper.w;
}
};
int dist[size];
vector<edge> g[size];
priority_queue<d> pri_que;
int main()
{
std::ios::sync_with_stdio(false);cin.tie(0);
int i,j;
int T;
cin >> T;
for (int cas=1;cas<=T;cas++){
cin >> n >> m;
while (!pri_que.empty()) pri_que.pop();
for (i=1;i<=n;i++) {
dist[i] = 0; g[i].clear();
}
while (m--){
int a,b,c;
cin >> a >> b >> c;
g[a].push_back(edge(b,c));
g[b].push_back(edge(a,c));
}
dist[1] = INF;
pri_que.push(d(INF,1));
while (!pri_que.empty()){
d T = pri_que.top();pri_que.pop();
if (dist[T.no] > T.w) continue;
for (i=0;i<g[T.no].size();i++){
int to = g[T.no][i].to;
int w = g[T.no][i].w;
if (min(w,dist[T.no]) > dist[to]){
dist[to] = min(w,dist[T.no]);
pri_que.push(d(dist[to],to));
}
}
}
cout << "Scenario #" << cas << ":" << endl;
cout << dist[n] << endl << endl;
}
return 0;
}