#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. mysql 添加外键

    create table class( cid tinyint unsigned primary key auto_increment, caption varchar(15) not null)en ...

  2. “windows的批处理”与“Linux的shell script”的类比学习

    从2005年开始,做了将近10年的系统维护,先是做网络接入管理,然后做网络安全与审计,然后做服务器管理等整个网络系统的运营管理:现在又兼着做一些Linux下的视频监控系统的软硬件维护.过程中遇到太多重 ...

  3. Linux硬件相关

    1)查看设备号/厂商号 http://blog.csdn.net/styshoo/article/details/51203881   二.硬件厂商 1)瑞传科技股份有限公司 https://www. ...

  4. iis日志分析软件及大文本切割软件下载

    在网上找了好几个日志分析软件,觉得这个是最简单.实用的,至少对我来说. 但这个软件有个缺点,就是日志比较大时,分析详细的会溢出,需要用到文本切割工具. 软件下载: iis日志分析软件 大文本切割软件 ...

  5. 使用RSS订阅

    1.绪论 对某一主题完成一次文献检索后,我们希望能持续了解该主题最新文献,即实现文献追踪. 为此,搜索引擎和数据库厂商(数据源)提供一般两种订阅服务:邮件和RSS.订阅后,数据源会自动推送最新信息,免 ...

  6. UI和View 三种控制方式

    AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xm ...

  7. linux网卡绑定脚本

    2013-08-20 15:30:51 此脚本适用于CentOS5.x和CentOS6.x. #!/bin/bash #**************************************** ...

  8. 【统一异常处理】@ControllerAdvice + @ExceptionHandler 全局处理 Controller 层异常

    1.利用springmvc注解对Controller层异常全局处理 对于与数据库相关的 Spring MVC 项目,我们通常会把 事务 配置在 Service层,当数据库操作失败时让 Service ...

  9. tomcat 配置域名访问应用

    <Host appBase="webapps" autoDeploy="true" name="www.XXX.com" unpack ...

  10. python+selenium环境配置及浏览器调用

    最近在学习python自动化,从项目角度和技术基础角度出发,我选择了python+selenium+appium的模式开始我的自动化测试之旅: 一.python安装 二.python IDE使用简介 ...