POJ 1502 MPI Maelstrom
2014-12-09 15:58
225 查看
http://poj.org/problem?id=1502
许久没写最短路 还是1A 哈哈!裸最短路!
许久没写最短路 还是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; }
相关文章推荐
- POJ 1502:MPI Maelstrom Dijkstra模板题
- poj-1502(MPI Maelstrom)
- poj 1502 MPI Maelstrom--dijkstra--atoi
- POJ 1502 MPI Maelstrom 单源最短路 Floyd Dijkstra
- POJ - 1502 MPI Maelstrom(最短路dijkstra)
- 【poj 1502】 MPI Maelstrom 【East Central North America 1996】
- POJ 1502 MPI Maelstrom BFS最短路
- POJ - 1502 MPI Maelstrom
- poj 1502 MPI Maelstrom
- POJ 1502:MPI Maelstrom Dijkstra模板题
- POJ 1502 MPI Maelstrom(单源最短路)
- POJ 1502 MPI Maelstrom (最短路)
- POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)
- POJ 1502 MPI Maelstrom(单源最短路|Dijkstra实现)
- Dijkstra-POJ-1502-MPI Maelstrom
- POJ 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
- poj 1502 MPI Maelstrom
- POJ 1502 MPI Maelstrom(spfa邻接矩阵)
- POJ--1502:MPI Maelstrom (最短路径:Dijkstra算法 & Floyd算法)