poj 1797 一条路径中的最小边 再找出最大的
2015-06-21 21:13
267 查看
Sample Input
1 // T
3 3// n m
1 2 3//u v w
1 3 4
2 3 5
Sample Output
Scenario #1:
4
# include <iostream> # include <cstdio> # include <cstring> # include <algorithm> # include <cmath> # define LL long long using namespace std ; const int MAXN=1010; const int INF=0x3f3f3f3f; int cost[MAXN][MAXN]; int lowcost[MAXN]; bool vis[MAXN]; int n ; void Dijkstra(int beg) { for(int i=1;i<=n;i++) { lowcost[i]=0; vis[i]=false; } lowcost[beg]=INF; for(int j=0;j<n;j++) { int k=-1; int Max=0; for(int i=1;i<=n;i++) if(!vis[i]&&lowcost[i]>Max) { Max=lowcost[i]; k=i; } if(k==-1)break; vis[k]=true; for(int i=1;i<=n;i++) if(!vis[i]&&min(lowcost[k],cost[k][i])>lowcost[i] ) lowcost[i]=min(lowcost[k],cost[k][i]); } } int main() { // freopen("in.txt","r",stdin) ; int T; int m; scanf("%d",&T); int iCase=0; while(T--) { iCase++; scanf("%d%d",&n,&m); memset(cost,0,sizeof(cost)); int u,v,w; while(m--) { scanf("%d%d%d",&u,&v,&w); cost[u][v]=cost[v][u]=max(cost[u][v],w); } Dijkstra(1); printf("Scenario #%d:\n",iCase); printf("%d\n\n",lowcost ); } return 0; }View Code
相关文章推荐
- Effective STL 条款3
- 人,绩效和职业道德有感
- 团队作业-第五周-运行及总结
- leetcode House Robber II
- .toString和String.valueOf()
- PS-
- HDU-5273
- 团队作业-第五周-测试与调试
- ubuntu平台hadoop2.6.0安装Hbase
- Tmux 速成教程:技巧和调整
- java基础—IO流——字节流的操作演示
- 【华为oj】字符串运用-密码截取
- ios开发-多线程GCD之详解
- java学习之旅01--如何学习
- ubuntu-查看iso文件的md5
- 《人,绩效和职业道德》与博客文章的读后感
- 谈谈Ext JS组件之引子
- JAVA类型修饰符(public,protected,private,friendly)
- [C#]剖析异步编程语法糖: async和await
- [Leetcode.python] 001. Two Sum