poj2387- Til the Cows Come Home
来源:互联网 发布:淘宝死人衣服分辨 编辑:程序博客网 时间:2024/05/21 09:03
Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u
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.
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.
* 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
注意是先输入道路数 在输入点的数量
#include<stdio.h>#include<string.h>#define MAX 99999999int n,m,s,t,j,k,i,c;int dis[10000];int vis[10000];int map[10000][10000];int dijstra (int x, int y){ int min; memset(vis,0,sizeof(vis)); for(i=1;i<=n;i++) dis[i]=map[x][i]; dis[x]=0; vis[x]=1; for(i=1;i<=n;i++) { min=MAX; for(j=1;j<=n;j++) { if(!vis[j]&&dis[j]<min) { min=dis[j]; k=j; } } vis[k]=1; for(j=1;j<=n;j++) { if(!vis[j]&&dis[j]>min+map[k][j]) { dis[j]=min+map[k][j]; } } } return dis[y];}int main(){ while(scanf("%d%d",&m,&n)!=EOF) { for(i=1;i<=n;i++) { for(j=1;j<=n;j++) { map[i][j]=map[j][i]=MAX; } } for(c=1;c<=m;c++) { int a,b,distance; scanf("%d%d%d",&a,&b,&distance); if(map[a][b]>distance) { map[a][b]=map[b][a]=distance; } } int mindis= dijstra(1,n); printf("%d\n",mindis); } return 0;}
0 0
- poj2387- Til the Cows Come Home
- poj2387- Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home【Dijkstra】
- POJ2387----Til the Cows Come Home(dijkstra)
- POJ2387---Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- [poj2387] Til the Cows Come Home
- poj2387 Til the Cows Come Home
- poj2387 Til the Cows Come Home
- poj2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- Poj2387- Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- POJ2387-Til the Cows Come Home
- POJ2387 Til the Cows Come Home
- HBase SI,一个不完善的HBase 分布式事务的解决方案
- Android开发入门:样式和主题(Styles and Themes)
- bzoj1096: [ZJOI2007]仓库建设 斜率优化DP
- 杭电 1005 Number Sequence()
- Extjs进度条超时解决
- poj2387- Til the Cows Come Home
- UVa12210 - A Match Making Problem(排序)
- 一个双击返回键退出的demo
- C++写日志源代码分析,可实现根据日期自动创建文件夹、日志分类、文件大小控制等
- Oracle入门-2存储过程
- HDU 1159 Common Subsequence (动规+最长公共子序列)
- TCP/IP模型及TCP/UDP协议
- css 常用样式
- Can't lock file (errno: 170) 错误