题意

给出图,从点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. 解析如何利用ElasticSearch和Redis检索和存储十亿信息

    如果从企业应用的生存率来看,选择企业团队信息作为主要业务,HipChat的起点绝非主流:但是如果从赚钱的角度上看,企业市场的高收益确实值得任何公司追逐,这也正是像JIRA和Confluence这样的智 ...

  2. nginx編譯

    openssl源码安装后,编译nginx-1.9.7或者openresty找不到OpenSSL的解决办法 http://blog.csdn.net/zhiyuan_2007/article/detai ...

  3. [CSS3] The different of Background-size between 'cover' and 'contain'

    'cover': The smaller axies of image (x axies) should match smaller axies (x axies) of container. So ...

  4. 2015级C++第2周实践项目

    [项目1 - 宣告"主权"] 你已经是CSDN博客主了,用IT人特有的方式,编一段程序.在屏幕上输出你想说的话.按要求公布博文,作为我们的开山之作. [项目2 - 胖子不想说体重] ...

  5. 浅析Java抽象类和接口的比較

    abstract class和interface是Java语言中对于抽象类定义进行支持的两种机制,正是因为这两种机制的存在,才赋予了Java强大的面向对象能力. abstract class和inte ...

  6. UVA 11294 - Wedding(Two-Set)

    UVA 11294 - Wedding 题目链接 题意:有n对夫妻,0号是公主.如今有一些通奸关系(男男,女女也是可能的)然后要求人分配在两側.夫妻不能坐同一側.而且公主对面一側不能有两个同奸的人,问 ...

  7. Android recycleView的研究和探讨

    RecyclerViewLibrary A RecyclerView libirary ,has some support, like headerAdapter/TreeAdapter,and Pu ...

  8. iOS学习必须了解的七大手势

    文章只要你有一点点基础应该就可以看的懂,文章只为学习交流 #import "ViewController.h" @interface ViewController () @prop ...

  9. ES task管理

    Task Management API The Task Management API is new and should still be considered a beta feature. Th ...

  10. CxImage 简单配置与使用

    CxImage 简单配置与使用 如果本篇文章还不能解决你在生成解决方案以及便宜过程中的问题 请参阅: http://blog.csdn.net/afterwards_/article/details/ ...