http://poj.org/problem?id=1502
许久没写最短路 还是1A 哈哈!裸最短路!
#include <queue>
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXV = 110;
const int INF = 0x3f3f3f3f;
int n;
int G[MAXV][MAXV];
void Init(){
for(int i=0; i<MAXV; i++){
for(int j=0; j<MAXV; j++)
G[i][j] = INF;
G[i][i] = 0;
}
}
int change(char *p){
int res = 0;
for(int i=0; p[i]!='\0'; i++)
res = res * 10 + p[i] - '0';
return res;
}
int dis[MAXV],vis[MAXV];
void SPFA(){
memset(dis, 0x3f, sizeof(dis));
memset(vis, 0, sizeof(vis));
vis[1] = 1, dis[1] = 0;
queue <int> Q;
Q.push(1);
while(!Q.empty()){
int u = Q.front();
Q.pop();
vis[u] = 0;
for(int v=1; v<=n; v++){
if(G[u][v] == INF) continue;
if(dis[v] > dis[u] + G[u][v]){
dis[v] = dis[u] + G[u][v];
if(vis[v]) continue;
Q.push(v);
vis[v] = 1;
}
}
}
}
int main(){
while(scanf("%d",&n) == 1){
Init();
for(int i=2; i<=n; i++)
for(int j=1; j<i; j++){
char tmp[1010];
cin >> tmp;
if(tmp[0] == 'x') G[i][j] = G[j][i] = INF;
else G[i][j] = G[j][i] = change(tmp);
}
SPFA();
int ans = -INF;
for(int i=1; i<=n; i++)
ans = max(ans, dis[i]);
cout << ans << endl;
}
///system("pause");
return 0;
}