题意

给出图,从点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的更多相关文章

  1. POJ-1502 MPI Maelstrom 迪杰斯特拉+题解

    POJ-1502 MPI Maelstrom 迪杰斯特拉+题解 题意 题意:信息传输,总共有n个传输机,先要从1号传输机向其余n-1个传输机传输数据,传输需要时间,给出一个严格的下三角(其实就是对角线 ...

  2. POJ 1502:MPI Maelstrom Dijkstra模板题

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6499   Accepted: 4036 Des ...

  3. POJ 1502 MPI Maelstrom (Dijkstra)

    题目链接:http://poj.org/problem?id=1502 题意是给你n个点,然后是以下三角的形式输入i j以及权值,x就不算 #include <iostream> #inc ...

  4. MPI Maelstrom(Dijkstra)

    http://poj.org/problem?id=1502 刷一道模板题稳定一下心情... Dijkstra求单源最短路,就是输入的时候注意下,是按下三角输入的(无向图),输入字符x表示i与j不通. ...

  5. POJ1502: MPI Maelstrom

    红果果的dijstra算法应用,这里采用邻接表存储图 小插曲:while(scanf("%d",&n))提交时内存超限,改成while(scanf("%d&quo ...

  6. poj1502 MPI Maelstrom(单源最短路)

    题意:表面乍一看output是输出最小值,但仔细研究可以发现,这个最小值是从点1到所有点所花时间的最小值,其实是访问这些节点中的最大值,因为只有访问了最长时间的那个点才算访问了所有点.所以求最短路之后 ...

  7. MPI Maelstrom(East Central North America 1996)(poj1502)

    MPI Maelstrom 总时间限制:  1000ms 内存限制:  65536kB 描述 BIT has recently taken delivery of their new supercom ...

  8. POJ 1502 MPI Maelstrom [最短路 Dijkstra]

    传送门 MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 5711   Accepted: 3552 ...

  9. 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 ...

随机推荐

  1. HDU3001 Traveling (状压dp+三进制+Tsp问题总结)

    (1)这道题最多可以走两次,所以有0, 1, 2三种状态,所以我们要用三进制 如果要用三进制,就要自己初始化两个数组, 一个是3的n次方,一个是三进制数的第几位的数字是什么 void init() { ...

  2. jquery-layer.closeAll不执行的错觉

    在使用ajax.form提交的时候,弹出了layer插件的页面,于是我想使用layer插件提供的layer.closeAll()方法讲这个弹出的页面关闭,但是尝试了很久不行,到底是为什么呢? 过了一段 ...

  3. hdu5351

    题目名称:MZL's Border 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5351 题意:给出fib 1 = b,fib2 = a ; fib  ...

  4. Yii2高速构建RESTful Web服务功能简单介绍

    Yii2相比Yii1而言,一个重大的改进是内置了功能完备的RESTful支持. 其内置RESTful支持提供了例如以下功能: 使用ActiveRecord的通用接口来高速构建原型: 应答格式协商(缺省 ...

  5. UVA - 10229 Modular Fibonacci 矩阵快速幂

                                 Modular Fibonacci The Fibonacci numbers (0, 1, 1, 2, 3, 5, 8, 13, 21, 3 ...

  6. linux怎么开启telnet服务

    1>编辑telent的配置文件/etc/xinetd.d/telnet 如下: (设置disable = no,也就是开启telnet服务) service telnet { disable = ...

  7. 亿财道APP赚钱攻略,亿财道,一个看广告年入36万的APP

            亿财道(http://etway.net/),一款看广告(传单)赚钱的软件,这是一项革新的广告产品,代替了以往的纸质传单.在商家节约成本的同时,还给阅读者佣金,推广也有相应提成比例. ...

  8. row_number函数的使用

    转 row_number函数的使用 SQL Server数据库ROW_NUMBER()函数的使用是本文我们要介绍的内容,接下来我们就通过几个实例来一一介绍ROW_NUMBER()函数的使用. 实例如下 ...

  9. UVa 12545 Bits Equalizer【贪心】

    题意:给出两个等长的字符串,0可以变成1,?可以变成0和1,可以任意交换s中任意两个字符的位置,问从s变成t至少需要多少次操作 先可以画个草图 发现需要考虑的就是 1---0 0---1 ?---0 ...

  10. FCC高级编程篇之Make a Person

    Make a Person Fill in the object constructor with the following methods below: getfirstname() getLas ...