POJ 1502 MPI Maelstrom(单源最短路)
来源:互联网 发布:淘宝密码找回 编辑:程序博客网 时间:2024/06/10 21:54
题目链接:kuangbin带你飞 专题四 最短路练习 G - MPI Maelstrom
题意
n个处理器,第一个处理器要广播消息到其他所有的处理器,求需要时间最短是多少(从第一个点出发,求到其他点最短路的最大值)
思路
没什么可说的,单源最短路,dijkstra。
代码
#include<iostream>#include<cstring>#include<cmath>#include<cstdio>#include<algorithm>#include<queue>using namespace std;const int N = 509;const int MAX = 0x3f3f3f3f;int d[N];bool vis[N];int v[N][N];int dijkstra(int n){ memset(vis, 0, sizeof(vis)); for(int i=1; i<=n; i++) d[i] = v[1][i]; d[1] = 0; vis[1] = 1; for(int i=1; i<n; i++) { int x = -1, mmin = MAX; for(int j=1; j<=n; j++) if(!vis[j] && d[j] < mmin) mmin = d[x = j]; if(x == -1) break; vis[x] = 1; for(int j=1; j<=n; j++) { if(!vis[j]) d[j] = min(d[j], d[x] + v[x][j]); } } int mmax = 0; for(int j=1; j<=n; j++) mmax = max(mmax, d[j]); return mmax;}int main(){ int n; scanf("%d", &n); memset(v, 0x3f3f3f3f, sizeof(v)); for(int i=2; i<=n; i++) { for(int j=1; j<i; j++) { char t[20]; scanf("%s", t); if(t[0] != 'x') { int k = 0; int x = 0; while(t[k] != '\0') x = x*10 + t[k++]-'0'; v[i][j] = v[j][i] = x; } } } printf("%d\n", dijkstra(n)); return 0;}
0 0
- POJ 1502 - MPI Maelstrom(单源最短路)
- POJ 1502 MPI Maelstrom(单源最短路)
- POJ 1502 - MPI Maelstrom(单源最短路)
- MPI Maelstrom poj 1502 单源最短路
- POJ 1502 MPI Maelstrom(单源最短路|Dijkstra实现)
- POJ 1502 MPI Maelstrom(单源最短路|Floyd实现)
- poj 1502 MPI Maelstrom(单源最短路dijkstra)
- POJ 1502 MPI Maelstrom 单源最短路 Floyd Dijkstra
- POJ 1502 MPI Maelstrom 【单源最短路中求最大值】
- poj 1502 MPI Maelstrom 单源最短路+dijkstra算法
- POJ 1502 MPI Maelstrom 最短路dijkstra
- poj 1502--MPI Maelstrom (最短路spfa)
- 【POJ】1502 MPI Maelstrom 最短路
- POJ 1502 MPI Maelstrom(最短路)
- POJ 1502 MPI Maelstrom 最短路
- POJ 1502MPI Maelstrom BFS最短路
- poj 1502 MPI Maelstrom(最短路)
- 最短路spfa POJ 1502 MPI Maelstrom
- 深入交流,发现更多--总结米老师语录
- 简单计时器
- 第一章 面向对象编程概述
- 【React Native开发】React Native进行签名打包成Apk(5)
- Tachyon源码结构分析(一)
- POJ 1502 MPI Maelstrom(单源最短路)
- Microsoft Visual Studio (VS)2010 常用快捷键大全 便捷开发
- Java EE-Eclipse再次配置Tomcat服务器问题
- 自己的半年学习总结--发文于2012-3-30
- 一位小白的初来乍到。
- office2010安装提示需要MSXML版本6.10.1129.0
- 一个艰难的开始
- Ansi、Unicode、UTF8字符串之间的转换和写入文本
- CODEFORCES #339 div2 A