#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std; #define INF 0xfffffff
#define N 1002 int n, m, G[N][N], vis[N], dist[N]; void IN()
{
memset(vis, 0, sizeof(vis)); for(int i=1; i<=n; i++)
{
dist[i]=INF;
for(int j=1; j<=i; j++)
{
G[i][j]=G[j][i]=INF;
}
}
} void DIST(int S, int E)
{
dist[S]=0; for(int i=1; i<=n; i++)
{
int index=1, MIN=INF;
for(int j=1; j<=n; j++)
{
if(vis[j]==0 && dist[j]<MIN)
MIN=dist[j], index=j;
} vis[index]=1;
for(int j=1; j<=n; j++)
{
if(vis[j]==0 && G[index][j]+dist[index]<dist[j])
{
dist[j]=G[index][j]+dist[index];
}
}
} cout << dist[E] << endl;
} int main()
{
while(scanf("%d%d", &m, &n)!=EOF)
{
int i, a, b, c; IN(); for(i=0; i<m; i++)
{
scanf("%d%d%d", &a, &b, &c); G[a][b]=G[b][a]=min(G[a][b], c);
} DIST(1, n);
}
return 0;
}

  

(最短路 弗洛伊德) Til the Cows Come Home -- POJ --2387的更多相关文章

  1. Til the Cows Come Home(poj 2387 Dijkstra算法(单源最短路径))

    Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 32824   Accepted: 11098 Description Bes ...

  2. kuangbin专题专题四 Til the Cows Come Home POJ - 2387

    题目链接:https://vjudge.net/problem/POJ-2387 题意:从编号为n的城市到编号为1的城市的最短路. 思路:dijkstra模板题,直接套板子,代码中我会带点注释给初学者 ...

  3. POJ 2387 Til the Cows Come Home (最短路 dijkstra)

    Til the Cows Come Home 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Bessi ...

  4. POJ 2387 Til the Cows Come Home 【最短路SPFA】

    Til the Cows Come Home Description Bessie is out in the field and wants to get back to the barn to g ...

  5. POj2387——Til the Cows Come Home——————【最短路】

    A - Til the Cows Come Home Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & ...

  6. POJ2387 Til the Cows Come Home (最短路 dijkstra)

    AC代码 POJ2387 Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to ...

  7. Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化)

    Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化) 贝西在田里,想在农夫约翰叫醒她早上挤奶之前回到谷仓尽可能多地睡一觉.贝西需要她的美梦,所以她想尽快回 ...

  8. POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)

    传送门 Til the Cows Come Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 46727   Acce ...

  9. Til the Cows Come Home(最短路)

    Til the Cows Come Home Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I ...

随机推荐

  1. 关于sortedlist 中值的添加,删除,索引测试.

    SortedList 类代表了一系列按照键来排序的键/值对,这些键值对可以通过键和索引来访问. 排序列表是数组和哈希表的组合.它包含一个可使用键或索引访问各项的列表.如果您使用索引访问各项,则它是一个 ...

  2. XStream将XML转javaben,出现多余的tag,导致出错

    今天在测试银联无卡快捷支付的案例时,多了一个多tag兼容性测试,它是指银联的XML报文中会出现多余的tag,如果我们用XStream解析的时候,没有Javabean的字段可以对应上,就会报错!提示: ...

  3. POJ2230 Watchcow

    原题链接 类欧拉回路,要求每条边被正反各经过一次,且从\(1\)出发并回到\(1\). 只需每次搜索该点的边时,将该点的边对应的邻接表头及时修改为下一条即可,因为邻接表恰好储存了正反方向的边,所以及时 ...

  4. java中 this 关键字的三种用法

    Java中this的三种用法 调用属性 (1)this可以调用本类中的任何成员变量 调用方法(可省略) (2)this调用本类中的成员方法(在main方法里面没有办法通过this调用) 调用构造方法 ...

  5. SPring中quartz的配置(可以用实现邮件定时发送,任务定时执行,网站定时更新等)

    http://www.cnblogs.com/kay/archive/2007/11/02/947372.html 邮件或任务多次发送或执行的问题: 1.<property name=" ...

  6. 模态框MODAL的一些事件捕捉

    下表列出了模态框中要用到事件.这些事件可在函数中当钩子使用. 事件 描述 实例 show.bs.modal 在调用 show 方法后触发. $('#identifier').on('show.bs.m ...

  7. Flex 得到一个对象的所有属性

    var obj:Object =..... ///需要处理的对象 fieldname:Array = ObjectUtil.getClassInfo(obj)["properties&quo ...

  8. [VBS]检测计算机各硬件信息

    1)批处理脚本:Rhea_HardwareInfoCollector.bat 调用VBScript脚本Rhea_HardwareInfoCollector.vbs,并将结果打印到文件Rhea_Resu ...

  9. Java第15章笔记

    字符串的概述 1.什么是字符串:零个或多个字符组成的有限序列 2.如何使用字符串:(使用字符串分为两步)          1)定义并初始化字符串          2)使用字符,对字符串进行一些处理 ...

  10. css兼容技巧

    CSS兼容常用技巧 请尽量用xhtml格式写代码,而且DOCTYPE影响 CSS 处理,作为W3C标准,一定要加DOCTYPE声明. 1.div的垂直居中问题 vertical-align:middl ...