http://poj.org/problem?id=1502

刷一道模板题稳定一下心情。。。

Dijkstra求单源最短路,就是输入的时候注意下,是按下三角输入的(无向图),输入字符x表示i与j不通。

可以这样输入:

if(scanf("%d",&w)) map[i][j] = map[j][i] = w;
else scanf("x");

 #include<stdio.h>
#include<string.h>
const int INF = 0x3f3f3f3f; int map[][],vis[],dis[],n;
void Dijkstra()
{
int i,j;
memset(vis,,sizeof(vis));
for(i = ; i < n; i++)
dis[i] = INF;
dis[] = ; for(i = ; i < n; i++)
{
int mindis = INF,pos;
for(j = ; j < n; j++)
{
if(!vis[j] && dis[j] < mindis)
{
mindis = dis[j];
pos = j;
}
}
vis[pos] = ;
for(j = ; j < n; j++)
{
if(!vis[j] && dis[j] > dis[pos]+map[pos][j])
dis[j] = dis[pos]+map[pos][j];
}
} } int main()
{
while(~scanf("%d",&n))
{
for(int i = ; i < n; i++)
for(int j = ; j < n; j++)
map[i][j] = INF;
for(int i = ; i < n; i++)
{
for(int j = ; j < i; j++)
{
int w;
if(scanf("%d",&w)) map[i][j] = map[j][i] = w;
else scanf("x");
}
}
Dijkstra();
int max = -;
for(int i = ; i < n; i++)
{
if(dis[i] > max)
max = dis[i];
}
printf("%d\n",max);
}
return ;
}

MPI Maelstrom(Dijkstra)的更多相关文章

  1. POJ 1502:MPI Maelstrom Dijkstra模板题

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

  2. POJ 1502 MPI Maelstrom (Dijkstra)

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

  3. POJ1502 MPI Maelstrom Dijkstra

    题意 给出图,从点1出发,求到最后一个点的时间. 思路 单源最短路,没什么好说的.注意读入的时候的技巧. 代码 #include <cstdio> #include <cstring ...

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

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

  5. POJ 1502 MPI Maelstrom

    MPI Maelstrom Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 20000/10000K (Java/Other) Total ...

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

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

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

  8. POJ 1502 MPI Maelstrom (最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6044   Accepted: 3761 Des ...

  9. POJ 1502 MPI Maelstrom(最短路)

    MPI Maelstrom Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4017   Accepted: 2412 Des ...

随机推荐

  1. 11.1 morning

    完美的序列(sequence)Time Limit:1000ms Memory Limit:64MB题目描述LYK 认为一个完美的序列要满足这样的条件:对于任意两个位置上的数都不相同.然而并不是所有的 ...

  2. SQL存储过程基于字段名传入的字符串拼接.

    --定义存储过程. Create PROCEDURE Usp_Static ), ), --分组字段. ), --统计字段. ), --表头字段. ) --聚会函数. AS ) --存储游标执行的列. ...

  3. Java 6 Thread States and Life Cycle.

    Ref: Java 6 Thread States and Life Cycle This is an example of UML protocol state machine diagram sh ...

  4. clientX 属性.

    Syntax: event.clientX The clientX event attribute returns the horizontal coordinate (according to th ...

  5. 查询两个日期(时间)以内的数据,between and 或 and 连>= <=,to_date()

    between and 方法 select * from kk.kkhmd where larq between(to_date('2008-9-3','yyyy-mm-dd')) and (to_d ...

  6. DATEDIFF interval=ms的用法

    datediff(ms,@CurrDateTime,@Date)>0 当上面的日期超过24天,用上面的sql会有问题 要修改成如下: (CONVERT(VARCHAR,@CurrDateTime ...

  7. 一个Socket数据处理模型

    Socket编程中,如何高效地接收和处理数据,这里介绍一个简单的编程模型. Socket索引 - SocketId 在给出编程模型之前,先提这样一个问题,程序中如何描述Socket连接? 为什么这么问 ...

  8. cocos2d-x 之 CCArray 源码分析

    cocos2d-x 自己实现了一个数组CCArray ,下面我们来分析一下CCArray的源码 CCArray继承CCObject,所以,CCArray也具有引用计数功能和内存自动管理功能. 数组的源 ...

  9. 【CF39E】【博弈论】What Has Dirichlet Got to Do with That?

    Description You all know the Dirichlet principle, the point of which is that if n boxes have no less ...

  10. Windows7 IIS7 无法启动计算机上的服务W3SVC如何修复

    错误提示 启动iis7管理服务器提示:无法启动计算机上的服务W3SVC 启动Windows Process Activation Service服务,报错:6801 指定资源管理器中的事务支持未启动或 ...