pku 1125 Stockbroker Grapevine(Floyd-Warshall)
2009-07-13 17:13
274 查看
Floyd-Warshall算法计算各点对之间的最短路径权值,最后把所有起始点遍历一下,选出满足要求的点。
// pku 1125.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <iostream> using namespace std; #define rm(x,y) (x=x<y?x:y)//replace if smaller int net[105][105]; int n; int main() { //freopen("d://1.txt","r",stdin); int i,j,k,con_point,time,start,least_time,temp; while(scanf("%d",&n)&&n) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { if(i!=j) net[i][j]=SHRT_MAX; else net[i][j]=0; } } for(i=1;i<=n;i++) { scanf("%d",&k); for(j=0;j<k;j++) { scanf("%d",&con_point); scanf("%d",&net[i][con_point]); } } for(k=1;k<=n;k++) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { rm(net[i][j],net[i][k]+net[k][j]); } } } least_time=SHRT_MAX; for(i=1;i<=n;i++) { temp=0; for(j=1;j<=n;j++) { if(i==j) continue; if(net[i][j]>temp) temp=net[i][j]; } if(temp<least_time) { start=i; least_time=temp; } } printf("%d %d/n",start,least_time); } return 0; }
相关文章推荐
- POJ 1125 Stockbroker Grapevine (FloydWarshall 所有点对最短路径)
- poj 1125 Stockbroker Grapevine——Floyd-Warshall算法
- POJ1125 Stockbroker Grapevine SPFA或Floyd
- pku1125 Stockbroker Grapevine
- poj-1125 Stockbroker Grapevine【floyd/dp经典题】
- POJ-1125 Stockbroker Grapevine (floyd)
- POJ 1125 Stockbroker Grapevine (Floyd最短路)
- Poj 1125 Stockbroker Grapevine(floyd小变形)
- poj 1125 Stockbroker Grapevine 【最短路 Floyd】
- poj 1125 Stockbroker Grapevine(floyd)
- POJ 1125 Stockbroker Grapevine(Floyd)
- POJ - 1125 Stockbroker Grapevine (动态规划理解floyd)
- POJ 1125 Stockbroker Grapevine(Floyd)
- POJ 1125 Stockbroker Grapevine(Floyd)
- [poj 1125]Stockbroker Grapevine[Floyd最短路]
- poj 1125 Stockbroker Grapevine 很好的一道floyd入门题
- POJ 1125 Stockbroker Grapevine (Floyd)
- (最短路-floyd+邻接矩阵)PKU-1125 Stockbroker Grapevine
- Pku acm 1125 Stockbroker Grapevine 动态规划题目解题报告(十九)
- pku 1125—Stockbroker Grapevine