(最短路 弗洛伊德) Til the Cows Come Home -- POJ --2387
#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的更多相关文章
- Til the Cows Come Home(poj 2387 Dijkstra算法(单源最短路径))
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 32824 Accepted: 11098 Description Bes ...
- kuangbin专题专题四 Til the Cows Come Home POJ - 2387
题目链接:https://vjudge.net/problem/POJ-2387 题意:从编号为n的城市到编号为1的城市的最短路. 思路:dijkstra模板题,直接套板子,代码中我会带点注释给初学者 ...
- 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 ...
- 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 ...
- POj2387——Til the Cows Come Home——————【最短路】
A - Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & ...
- 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 ...
- Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化)
Til the Cows Come Home 最短路Dijkstra+bellman(普通+优化) 贝西在田里,想在农夫约翰叫醒她早上挤奶之前回到谷仓尽可能多地睡一觉.贝西需要她的美梦,所以她想尽快回 ...
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- Til the Cows Come Home(最短路)
Til the Cows Come Home Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I ...
随机推荐
- thinkphp装修平台源码
每日签到微擎微赞自助授权中心站长工具(new)☜=每日新帖=微信开发手册VIP优惠活动 开启辅助访问切换到宽版 用户名 自动登录 找回密码 密码 登录 立即注册 只需一步,快速开始 首页 微鱼商业 ...
- JAVA课堂动手动脑实验--方法的重载定义,组合数的递归算法
1. 请看以下代码,你发现了有什么特殊之处吗? 答:此程序中的两个方法虽然方法名一样,但是参数的数据类型不同: 这是方法的重载,方法的重载需要满足的条件: 1)方法名相同: 2)参数类型不同,参数个数 ...
- thread库,附带程序介绍
千万注意线程不要比主线程晚结束,主线程一旦结束,对象将被销毁 std:thread 代表了一个线程对象 this_thread:是一个命名空间,对当前调用者线程进行操作 如果把可调用对象作为参数传递给 ...
- Array Division 808D
D. Array Division time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- How to use bmw icom a2
Lan Connect Operation Details 1. Connect the LAN cable to ICOM A1/ICOM A2, another side to laptop LA ...
- Jsonpath的基本使用
JSONPath - 是xpath在json的应用. xml最大的优点就有大量的工具可以分析,转换,和选择性的提取文档中的数据.XPath是这些最强大的工具之一. 如果可以使用xpath来解析js ...
- Python数据库工具类MySQLdb使用
MySQLdb模块用于连接mysql数据库. 基本操作 # -*- coding: utf-8 -*- #mysqldb import time, MySQLdb ...
- jQuery操作(一)
基本语法:$(selector).action() 寻找元素(重要的选择器和筛选器) 一:选择器 1.1 基本选择器: $("*") $("#id") $(&q ...
- JSP动作
JSP动作元素在请求处理阶段起作用,他们会被转换成Java代码来执行操作,如访问一个Java对象或调用方法. JSP动作元素是用XML语法写成的. 动作元素基本上都是预定义的函数,JSP规范定义了一系 ...
- swift MD5 加密方法
引入OC类库 md5.h: #import <UIKit/UIKit.h> @interface Md5Controller : UIViewController @end md5.m: ...