http://vijos.org/p/1391
SPFA,感觉不是真正意义上的SPFA。。
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#define ms(i,j) memset(i, j, sizeof(i));
using namespace std;
const int maxn = 2000 + 5;
int w[maxn][maxn];
int edge[maxn][maxn];
int dis[maxn];
int ex[maxn];
queue<int> q;
int n;
int main ()
{
scanf("%d", &n);
int a,b,c;
for (int i=1;i<=n;i++)for (int j=1;j<=n;j++) w[i][j]=100000000;
while (scanf("%d%d%d", &a, &b, &c)==3&&(a||b||c))
{
w[a][b]=c;
}
ms(dis,0);ms(ex,false);
dis[1] = 100000000;ex[1]=true;
q.push(1);
while(!q.empty())
{
int u = q.front();q.pop();ex[u]=false;
for (int i=1;i<=n;i++)
{
if (w[u][i]!=100000000&&dis[i]<min(dis[u], w[u][i]))
{
dis[i]=min(dis[u], w[u][i]);
if (!ex[i])
{
ex[i]=true;
q.push(i);
}
}
}
}
for (int i=2;i<=n;i++) printf("%d\n", dis[i]);
return 0;
}