POJ1502 MPI Maelstrom Dijkstra
题意
给出图,从点1出发,求到最后一个点的时间。
思路
单源最短路,没什么好说的。注意读入的时候的技巧。
代码
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1000000000;
const int maxn = 110;
int n;
int edge[maxn][maxn];
int d[maxn];
bool used[maxn];
void dijkstra(int s)
{
d[s] = 0;
while(true) {
int v = -1;
for(int i = 1 ; i <= n ; i ++) {
if(!used[i]) {
if(v == -1 || d[i] < d[v]) v = i;
}
}
if(v == -1) break;
used[v] = true;
for(int i = 1 ; i <= n ; i ++) {
d[i] = min(d[i],d[v]+edge[v][i]);
}
}
}
int main()
{
//freopen("in.txt","r",stdin);
fill(d,d+maxn,INF);
memset(used,false,sizeof(used));
for(int i = 0 ; i < maxn ; i ++) {
fill(edge[i],edge[i]+maxn,INF);
edge[i][i] = 0;
}
scanf("%d",&n);
for(int i = 2 ; i <= n ; i ++) {
for(int j = 1 ; j < i ; j ++) {
int tmp;
char getit;
if(scanf("%d",&tmp))
edge[i][j] = edge[j][i] = tmp;
else scanf("%c",&getit);
}
}
dijkstra(1);
int ma = d[1];
for(int i = 2 ; i <= n ; i ++) {
ma = max(d[i],ma);
}
cout << ma << endl;
return 0;
}
POJ1502 MPI Maelstrom Dijkstra的更多相关文章
- POJ-1502 MPI Maelstrom 迪杰斯特拉+题解
POJ-1502 MPI Maelstrom 迪杰斯特拉+题解 题意 题意:信息传输,总共有n个传输机,先要从1号传输机向其余n-1个传输机传输数据,传输需要时间,给出一个严格的下三角(其实就是对角线 ...
- POJ 1502:MPI Maelstrom Dijkstra模板题
MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 6499 Accepted: 4036 Des ...
- POJ 1502 MPI Maelstrom (Dijkstra)
题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...
- MPI Maelstrom(Dijkstra)
http://poj.org/problem?id=1502 刷一道模板题稳定一下心情... Dijkstra求单源最短路,就是输入的时候注意下,是按下三角输入的(无向图),输入字符x表示i与j不通. ...
- POJ1502: MPI Maelstrom
红果果的dijstra算法应用,这里采用邻接表存储图 小插曲:while(scanf("%d",&n))提交时内存超限,改成while(scanf("%d&quo ...
- poj1502 MPI Maelstrom(单源最短路)
题意:表面乍一看output是输出最小值,但仔细研究可以发现,这个最小值是从点1到所有点所花时间的最小值,其实是访问这些节点中的最大值,因为只有访问了最长时间的那个点才算访问了所有点.所以求最短路之后 ...
- MPI Maelstrom(East Central North America 1996)(poj1502)
MPI Maelstrom 总时间限制: 1000ms 内存限制: 65536kB 描述 BIT has recently taken delivery of their new supercom ...
- POJ 1502 MPI Maelstrom [最短路 Dijkstra]
传送门 MPI Maelstrom Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5711 Accepted: 3552 ...
- POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom /ZOJ 1291 MPI Maelstrom (最短路径)
POJ 1502 MPI Maelstrom / UVA 432 MPI Maelstrom / SCU 1068 MPI Maelstrom / UVALive 5398 MPI Maelstrom ...
随机推荐
- JS中的五种去重方法
JS中的五种去重方法 第一种方法: 第二种方法: 第三种方法: 第四种方法: 第五种方法:优化遍历数组法 思路:获取没重复的最右一值放入新数组 * 方法的实现代码相当酷炫,* 实现思路:获取没重复的 ...
- apche本地测试,无法访问此网站
- 【codeforces 501D】Misha and Permutations Summation
[题目链接]:http://codeforces.com/problemset/problem/501/D [题意] 给你两个排列; 求出它们的字典序num1和num2; 然后让你求出第(num1+n ...
- Mysql 5.7 官方文档翻译
始于 2017年4月1日-愚人节 1.1 MySQL 5.7 新功能 本章节介绍了MySQL 5.7 新版本中新增.废弃.删除的功能. 在1.5章节 Section 1.5, "Server ...
- SQL SERVER-union
UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的每个 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每个 SELECT 语句中 ...
- 各种List、Map、Set的比較
前言:Java中用不同的数据结构(哈希表/动态数组/平衡树/链表)实现了不同的集合接口(List/Map/Set).大多数情况下,集合类被用于不须要线程安全地环境,所以后来的集合实现都没有再採用同步以 ...
- 怎样訪问pcie整个4k的配置空间
眼下用于訪问PCIe配置空间寄存器的方法须要追溯到原始的PCI规范. 为了发起PCI总线配置周期,Intel实现的PCI规范使用IO空间的CF8h和CFCh来分别作为索引和数据寄存器,这样的方法能够訪 ...
- zzulioj--1719--小胖的疑惑(整数划分+dp打表)
1719: 小胖的疑惑 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 108 Solved: 51 SubmitStatusWeb Board De ...
- java中对象和对象引用的区别
1.何谓对象? 在Java中有一句比较流行的话,叫做“万物皆对象”,这是Java语言设计之初的理念之一.要理解什么是对象,需要跟类一起结合起来理解.下面这段话引自<Java编程思想>中的一 ...
- 092117-6265-01.dmp 蓝屏日志文件
Microsoft (R) Windows Debugger Version 10.0.15063.137 AMD64 Copyright (c) Microsoft Corporation. All ...