#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. 10.22JS日记

    1.js数据类型分析 (1)基础类型:string.number.boolean.null.undefined (2)引用类型:object-->json.array... 2.点运算  xxx ...

  2. 1F - A+B for Input-Output Practice (III)

    Your task is to Calculate a + b. Input Input contains multiple test cases. Each test case contains a ...

  3. sublime 注释模版插件DocBlockr的使用

    一.gihub地址 https://github.com/spadgos/sublime-jsdocs/ 其中有使用的教程可以参考 二.配置示例 安装教程此处略,请自行查找教程 jsdocs_extr ...

  4. iOS.Animation.CAMediaTiming

    CAMediaTiming Protocol CALayre 和 CAAnimation 实现了CAMediaTiming 接口. CAMediaTiming 定义了8个属性. speed属性: Co ...

  5. spring+mybatis+mina+logback框架搭建

    第一次接触spring,之前从来没有学过spring,所以算是赶鸭子上架,花了差不多一个星期来搭建,中间遇到各种各样的问题,一度觉得这个框架搭建非常麻烦,没有一点技术含量,纯粹就是配置,很低级!但随着 ...

  6. node.js 在使用child_process 模块时候,调试端口占用的问题解决方案(EADDRINUSE)

    在fork的时候,带参数{ execArgv: ['--debug=' + (process.debugPort +   1)] }

  7. jsonp,ajax,json问题

    JSONP技术 JSONP是解决跨域问题的一种常见方式 跨域问题,因为浏览器有同源策略,所以当不同域间进行数据交互的时候就会出现跨域问题 同源策略:只有在同协议.同域名.同端口的情况下才能进去数据交互 ...

  8. Windows 修改的hosts记录没有效果

    windows修改的hosts记录没有效果,新添加的也没有效果. 检查DNS设置相关的均正常, <Dns client为此计算机解析和缓冲域名系统 (DNS) 名称.> 为此计算机注册并更 ...

  9. MVC 模式和模型 2

    MVC框架 一个实现 MVC 模式的应用包含模型.视图.控制器 3 个模块: 模型:封装了应用的数据和业务逻辑,负责管理系统业务数据 视图:负责应用的展示 控制器:负责与用户进行交互,接收用户输入.改 ...

  10. [转]sqlmap使用教程

    sqlmap也是渗透中常用的一个注入工具,其实在注入工具方面,一个sqlmap就足够用了,只要你用的熟,秒杀各种工具,只是一个便捷性问题,sql注入另一方面就是手工党了,这个就另当别论了. 今天把我一 ...