图论专题(二)POJ1125最短路
来源:互联网 发布:it服务工程师培训 编辑:程序博客网 时间:2024/05/16 06:28
//题目连接:http://poj.org/problem?id=1125
//本题是基本的最短路问题
#include<stdio.h>#include<stdlib.h>#include<iostream>#include<math.h>#include<string.h>#include<vector>#include<algorithm>#include<stack>#include<queue>using namespace std;struct node{ int dis , wz; bool operator < (node a)const { if(dis > a.dis)return 1; return 0; }}test[111];int n,map[111][111];vector<int>pass[111];int bellman(int x){ bool vis[111]; priority_queue<node> m; for(int i = 1 ; i <= n ; i++) { test[i].dis = 0x3f3f3f; test[i].wz = i; } memset(vis,0,sizeof(vis)); vis[x] = 1; vector<int>::iterator it; int t = x; test[t].dis = 0; for(int i = 1 ; i <= n ; i++) { for(it = pass[t].begin() ; it < pass[t].end() ; it++) { if(test[*it].dis > test[t].dis + map[t][*it]) { test[*it].dis = test[t].dis + map[t][*it]; m.push(test[*it]); } } bool cas = 1; while(!m.empty() && cas) { node a = m.top(); if(!vis[a.wz]) { cas = 0; t = a.wz; vis[a.wz] = 1; } else cas = 1; m.pop(); } // if(m.empty())break; } int ans = 0; for(int i = 1 ; i <= n ; i++) { if(test[i].dis == 0x3f3f3f)return 0x3f3f3f; ans = max(ans,test[i].dis); } return ans;}int main(){ while(scanf("%d",&n) && n != 0) { for(int i = 1 ; i <= n ; i++) { int pair,x,y; pass[i].clear(); scanf("%d",&pair); for(int j = 1 ; j <= pair ; j++) { scanf("%d%d",&x,&y); map[i][x] = y; pass[i].push_back(x); } } int res = 0x3f3f3f; int ll ; for(int i = 1 ; i <= n ; i++) { int pp = bellman(i) ; if(res > pp) { res = pp; ll = i; } } if(res == 0x3f3f3f)printf("disjoint\n"); else printf("%d %d\n",ll,res); }}
- 图论专题(二)POJ1125最短路
- poj1125 最短路floyd
- poj1125最短路模板
- poj1125(floyd最短路)
- 【最短路】poj1125 Floyd
- poj1125(Floyd)最短路问题
- poj1125 floyed 求最短路
- poj1125 Stockbroker Grapevine 最短路
- 【POJ1125】Stockbroker Grapevine 最短路
- 最短路(poj1502 poj3259 poj1125)
- poj1125(最短路floyd算法)
- poj1125 Stockbroker Grapevine-最短路
- 图论专题总结—最短路
- 图论专题小结:最短路算法
- 最短路专题二(spfa)
- 最短路--floyed-warshall算法poj1125
- POJ1125 Stockbroker Grapevine(最短路Floyed)
- POJ1125 Stockbroker Grapevine(最短路floyd算法)
- float浮点数的二进制存储方式及转换
- 颜色的牌--推理题
- Android调用系统自带的下载程序进行下载。
- 第五周实验报告任务1-1
- 学习Windows Phone 7手机开发:后台任务之播放音乐
- 图论专题(二)POJ1125最短路
- 绝好html速成教程,简单易懂!!!
- 正整数类
- android基础——界面布局(二) 线性布局
- bat
- [STM32学习笔记2]SysTick定时器 - [ARM]
- 杭电ACM 1013 Digital Roots
- Linux设备驱动程序学习(0)-Hello, world!模块
- java +myeclipse 实现webservice