POJ-2387 Til the Cows Come Home ( 最短路 )
题目链接: http://poj.org/problem?id=2387
Description
Farmer John's field has N (2 <= N <= 1000) landmarks in it,
uniquely numbered 1..N. Landmark 1 is the barn; the apple tree grove in
which Bessie stands all day is landmark N. Cows travel in the field
using T (1 <= T <= 2000) bidirectional cow-trails of various
lengths between the landmarks. Bessie is not confident of her navigation
ability, so she always stays on a trail from its start to its end once
she starts it.
Given the trails between the landmarks, determine the minimum
distance Bessie must walk to get back to the barn. It is guaranteed
that some such route exists.
Input
* Lines 2..T+1: Each line describes a trail as three space-separated
integers. The first two integers are the landmarks between which the
trail travels. The third integer is the length of the trail, range
1..100.
Output
Sample Input
5 5
1 2 20
2 3 30
3 4 20
4 5 20
1 5 100
Sample Output
90 最短路模板题,求1到n的最短路
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<stack>
#include<queue> using namespace std; int way[][];
bool flag[];
int main(){
ios::sync_with_stdio( false ); int n, m; while( cin >> m >> n ){
int x, y, d;
memset( way, 0x3f3f3f3f, sizeof( way ) );
memset( flag, false, sizeof( flag ) );
for( int i = ; i < m; i++ ){
cin >> x >> y >> d;
way[x][y] = way[y][x] = min( way[x][y], d );
} for( int k = ; k < n - ; k++ ){
int minv = 0x3f3f3f3f, mini; for( int i = ; i < n; i++ ){
if( !flag[i] && minv > way[n][i] ){
minv = way[n][i];
mini = i;
}
} flag[mini] = true;
for( int i = ; i < n; i++ ){
if( !flag[i] ){
way[n][i] = min( way[n][i], way[n][mini] + way[mini][i] );
}
}
} cout << way[n][] << endl;
} return ;
}
POJ-2387 Til the Cows Come Home ( 最短路 )的更多相关文章
- POJ 2387 Til the Cows Come Home(最短路模板)
题目链接:http://poj.org/problem?id=2387 题意:有n个城市点,m条边,求n到1的最短路径.n<=1000; m<=2000 就是一个标准的最短路模板. #in ...
- POJ 2387 Til the Cows Come Home --最短路模板题
Dijkstra模板题,也可以用Floyd算法. 关于Dijkstra算法有两种写法,只有一点细节不同,思想是一样的. 写法1: #include <iostream> #include ...
- POJ 2387 Til the Cows Come Home (图论,最短路径)
POJ 2387 Til the Cows Come Home (图论,最短路径) Description Bessie is out in the field and wants to get ba ...
- POJ.2387 Til the Cows Come Home (SPFA)
POJ.2387 Til the Cows Come Home (SPFA) 题意分析 首先给出T和N,T代表边的数量,N代表图中点的数量 图中边是双向边,并不清楚是否有重边,我按有重边写的. 直接跑 ...
- POJ 2387 Til the Cows Come Home
题目链接:http://poj.org/problem?id=2387 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K ...
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
传送门 Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 46727 Acce ...
- 怒学三算法 POJ 2387 Til the Cows Come Home (Bellman_Ford || Dijkstra || SPFA)
Til the Cows Come Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 33015 Accepted ...
- 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 ...
- POJ 2387 Til the Cows Come Home Dijkstra求最短路径
Til the Cows Come Home Bessie is out in the field and wants to get back to the barn to get as much s ...
随机推荐
- python创建虚拟环境(Windows)
>>>构建Python虚拟环境的目的是为了防止真实环境被破坏!!! >>>每一个项目建议用一个虚拟环境为了防止软件版本号冲突!!! 1.在终端切换到一个新的磁盘 如 ...
- xpath beautiful pyquery三种解析库
这两天看了一下python常用的三种解析库,写篇随笔,整理一下思路.太菜了,若有错误的地方,欢迎大家随时指正.......(conme on.......) 爬取网页数据一般会经过 获取信息-> ...
- 3、大型项目的接口自动化实践记录----开放API练习
开始做实际项目前,先拿个网上的简单API练下手 一.API说明: 接口信息 接口名:京东获取单个商品价格 地址:http://p.3.cn/prices/mgets 入参:skuids=J_商品ID& ...
- Activiti6系列(5)- 核心API
前言 本来想把<疯狂工作流讲义-activiti6.0>这本书里面的实例拿过来,但是这本书我看完后,认为里面编写的activiti6的核心API代码片段不是很清晰,有不少需要雕琢的地方才好 ...
- 二、java实现多线程的方式?
一.同步?异步? 下面两幅图解释了同步异步. 二.实现多线程的方式 1.继承Thread package threaddemo; class CreateThreadDemo extends Thre ...
- 使用ArrayPool池化大型数组(翻译)
原文链接:https://adamsitnik.com/Array-Pool/ 使用ArrayPool 简介 .NET的垃圾收集器(GC)实现了许多性能优化,其中之一就是,设定年轻的对象很快消亡,然而 ...
- 垂直渐变的Button
public partial class RoundButton : Button { Rectangle r; private Brush _myBrush = null; , , ); , , ) ...
- 如何在GitHub上上传自己本地的项目?(很适合新手使用哦!)
这是我看了一些大佬们的博客后,尝试了几次,终于成功了上传项目,所以想做一下总结,以便以后查看,同时想分享给才接触GitHub的新手们,希望能够有所帮助~ 条条大路通罗马,上传的方法肯定不止一种,等我学 ...
- 整合-flowable-modeler,第一篇
BPMN流程想必大家都不陌生,经过这十几年的不断发展完善,在处理业务流程操作已经相当完善,我这里先不进行流程引擎的具体描述,单对集成流程设计器这块进行笔记,如有不对,跪求指出.
- MQTT服务器(Win)
系统环境准备 Java JDK >=1.6,系统环境变量配置JAVA HOME 链接:https://pan.baidu.com/s/1OO-KCdsCrdfjMtf6BVNl6Q 提取码:dy ...