题目链接:http://poj.org/problem?id=1797
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
const int N = 1e3 + 10;
int n,m;
int a[N][N],d[N],inq[N];
void SPFA(int s)
{
memset(d,0,sizeof(d));
memset(inq,0,sizeof(inq));
d[s] = INF;
queue<int> q;
q.push(s);
while(!q.empty()) {
int u = q.front();q.pop();
inq[u] = 0;
for(int v = 1; v <= n; v++)
if(d[v] < min(d[u],a[u][v])) {
d[v] = min(d[u],a[u][v]);
if(!inq[v]) {
inq[v] = 1;
q.push(v);
}
}
}
}
int main()
{
int T;
scanf("%d",&T);
for(int k = 1; k <= T; k++) {
memset(a,0,sizeof(a));
scanf("%d%d",&n,&m);
int u,v,w;
for(int i = 0; i < m; i++) {
scanf("%d%d%d",&u,&v,&w);
a[u][v] = a[v][u] = w;
}
SPFA(1);
printf("Scenario #%d:\n%d\n\n",k,d[n]);
}
return 0;
}