poj-2387 Til the Cows Come Home
来源:互联网 发布:java成绩代码 编辑:程序博客网 时间:2024/05/18 13:26
题目链接:http://poj.org/problem?id=2387
dij 注意判重边
#include <iostream>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <time.h>using namespace std;const int MAXV = 4010;const int inf = 10000000;int map[MAXV][MAXV];int d[MAXV];bool vis[MAXV];int n,m;void dijkstra(int s){for(int i=1;i<=n;i++) {vis[i]=0;d[i]=map[s][i];}while (1) {int min=inf,v = -1;for(int i=1;i<=n;i++)if(!vis[i] && d[i]<min){v=i;min=d[i];} if(v == -1) break;vis[v]=1;for(int i=1;i<=n;i++)if(!vis[i] && d[i] > d[v] + map[v][i])d[i]=map[v][i]+d[v];}}int main(){int i,j,a,b,c;while(scanf("%d%d",&m,&n) != EOF) { for(i=1;i<=n;i++) for(j=1;j<=n;j++) { if(i==j) map[i][i]=0; else map[i][j]=map[j][i]=inf; } for(i=1;i<=m;i++) { scanf("%d%d%d",&a,&b,&c); if(map[a][b]>c) map[a][b]=map[b][a]=c; }dijkstra(1);printf("%d\n",d[n]);}return 0;}
0 0
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- Poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ-2387-Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- poj 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- POJ 2387 Til the Cows Come Home
- iOS之Block代码块的定义及使用
- LINUX_004:将脚本放到后台执行——加nohup与不加nohup的区别
- 在windows中为vpn 连接添加静态路由
- 浅谈MindManager脑图之项目管理甘特图
- 使用SQLiteManager将Excel表格中的数据导入sqlite3数据库
- poj-2387 Til the Cows Come Home
- Android BlueDroid(二)
- Android桌面悬浮窗效果实现,仿360手机卫士悬浮窗效果
- Kafka深度解析
- 流程图工具
- LeetCode --- 6. ZigZag Conversion
- .net实现加密算法小结
- LeetCode --- 7. Reverse Integer
- 数据库 MySQL 常用命令