#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. JavaScript DOM操作浅谈

    1.理解DOM: DOM(Document Object Model ,文档对象模型)一种独立于语言,用于操作xml,html文档的应用编程接口. 怎么说,我从两个角度理解: 对于JavaScript ...

  2. DtCMS 在IIS7.0 下之伪静态

    1)首先新建一个应用程序池,名称任意,比如:nettest,托管管道模式先暂时设置为集成模式,等下面的一系列设置完成之后再设置成经典模式: 2)部署好站点,并将此站点的应用程序池设置为nettest; ...

  3. zz Alex's BLOG 串口连接

    using System; using System.Collections.Generic;using System.ComponentModel;using System.Data;using S ...

  4. Python 之异常处理机制

    python在程序运行出现错误时时有相应的反应机制 ,我们可以针对不同的错误做出不同的响应 list1 = ['a','b','c'] print(list1[4]) #>>>Ind ...

  5. mysql 查询 所有 父节点 单表

    SELECT T2.* FROM ( SELECT @r AS _id, ( SELECT @r := parent_id FROM tp_module_rel WHERE REL_ID = _id ...

  6. ''TclError: no display name and no $DISPLAY environment variable''解决方法

    在模块前写入一下代码: import matplotlib matplotlib.use('Agg') import matplotlib.pyplot as plt 具体解释见   http://m ...

  7. 【机器学习】感知机学习算法(PLA)

    感知机问题学习算法引入:信用卡问题 根据已知数据(不同标准的人的信用评级)训练后得出一个能不能给新客户发放信用卡的评定结果 解决该问题的核心思想扔为之前所讲到的梯度下降算法,对于更多条件的类似问题,首 ...

  8. [C#.NET]最简单的实现文本框的水印效果

    C#项目开发中在设计登录界面时,经常会遇到TextBox的水印提示要求.这里简单描述一下项目在实现水印提示的过程设置.如下图图1所示. 图1  窗体布局 一.窗体布局(如图1所示) 1.  在窗体中放 ...

  9. DOM-查找和修改

    1. 查找: 按HTML查找: 问题: 每次只能按一个条件查找,如果查找条件复杂,则步骤很繁琐 解决: 选择器: 按选择器查找: 2个API 1. 只查找一个元素: var elem=parent.q ...

  10. redis2

    一.安装redis 1)     下载redis安装包 可去官网http://redis.io ,也可通过wget命令, wget http://download.redis.io/redis-sta ...