|Vijos|图论最短路|P1391 想越狱的小杉
2016-08-20 22:55
381 查看
http://vijos.org/p/1391
SPFA,感觉不是真正意义上的SPFA。。
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; }
相关文章推荐
- 【vijos】【spfa最短路】想越狱的小杉
- 【vijos】【图论】【最短路径】【SPFA】想越狱的小杉
- 【图论-最短路变形】想越狱的小杉
- |Vijos|图论最短路|P1046 观光旅游
- |Vijos|图论最短路|P1082 丛林冒险
- Vijos 1391 想越狱的小杉
- |Vijos|图论最短路|P1446 最短路上的统计
- |Vijos|图论最短路|P1155 集合位置
- Vijos 1082 最短路
- [图论训练]BZOJ 3245: 最快路线【最短路】
- 【codevs 1041】【vijos P1119】[NOIP提高组2001] Car的旅行路线(最短路)
- poj 2139 Six Degrees of Cowvin Bacon 图论 Floyd最短路
- [spfa]SSL 1535 想越狱的小杉
- Codeforces Round #302 (Div. 2) D - Destroying Roads 图论,最短路
- 图论基础_最短路
- Vijos P1389婚礼上的小杉
- POJ 2387 图论之最短路【三种写法】
- hoj 2012 winter training Graph Day1 106 miles to Chicago图论最短路dijkstra算法
- ZOJ 3710 Friends(思维,最短路,图论)
- 图论算法(5) --- 双向广搜求最短路(Bidirectional Breadth First Search)