博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2387 Dijkstra 模板
阅读量:4480 次
发布时间:2019-06-08

本文共 1939 字,大约阅读时间需要 6 分钟。

Til the Cows Come Home
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 21209   Accepted: 7062

Description

Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get back as quickly as possible. 
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

* Line 1: Two integers: T and N 
* 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

* Line 1: A single integer, the minimum distance that Bessie must travel to get from landmark N to landmark 1.

Sample Input

5 51 2 202 3 303 4 204 5 201 5 100

Sample Output

90

直接求最短路: 代码:
View Code
1 #include 
2 #include
3 #include
4 using namespace std; 5 6 const int INF=9999999; 7 8 int map[1005][1005],vis[1005]; 9 int dis[1005];10 int t,n;11 12 void dijkstra(int s,int t)13 {14 int i,j,k,min;15 for(i=0;i
d)62 {63 map[x-1][y-1]=d;64 map[y-1][x-1]=d;65 }66 }67 dijkstra(0,n-1);68 }69 return 0;70 }

转载于:https://www.cnblogs.com/shenshuyang/archive/2012/08/02/2619326.html

你可能感兴趣的文章
【P2564】生日礼物(单调队列)
查看>>
Instuments工具
查看>>
新创建django项目,但网页打不开127.0.0.1:8000
查看>>
Python练习-内置函数的应用
查看>>
洛谷P3905 道路重建
查看>>
数据表格 - DataGrid - 行编辑
查看>>
HQL查询语句
查看>>
jsp听课笔记(四)
查看>>
vim
查看>>
数组的键/值操作函数
查看>>
Android单点触控与多点触控切换的问题解决方案
查看>>
JS常用函数与方法
查看>>
十、Shell基础
查看>>
py16 面向对象深入
查看>>
CentOS 7 安装 Gitlab
查看>>
JavaScript-03-常见函数
查看>>
ajax 设置Access-Control-Allow-Origin实现跨域访问
查看>>
去掉ExpandableListView的箭头图标
查看>>
[LeetCode]Binary Tree Level Order Traversal II
查看>>
跨页面传值自动刷新 操作文本与文件夹
查看>>