POJ 2387 Til the Cows Come Home 最短路-Dijkstra
来源:互联网 发布:js怎么隐藏按钮 编辑:程序博客网 时间:2024/05/01 03:56
题目地址: http://poj.org/problem?id=2387
模板题,直接上代码:
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <cstring>#include <string>#include <algorithm>#include <vector>#include <set>#include <map>#include <queue>using namespace std;/*freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);*/const int INF=0x3f3f3f3f;int n;int edge[1005][1005],s[1005],dis[1005];void Dijkstra(int be){ int i,j,temp,k; for(i=1;i<=n;i++) { dis[i]=edge[be][i]; s[i]=0; } s[be]=1;dis[be]=0; for(i=1;i<=n;i++) { temp=INF;k=1; for(j=1;j<=n;j++) if(!s[j]&&dis[j]<temp) { k=j;temp=dis[j]; } s[k]=1; for(j=1;j<=n;j++) if(!s[j]&&dis[j]>dis[k]+edge[k][j]) dis[j]=dis[k]+edge[k][j]; }}int main(){ int i,j,t; while(cin>>t>>n) { memset(edge,INF,sizeof(edge)); while(t--) { int a,b,c; scanf("%d%d%d",&a,&b,&c); if(edge[a][b]>c) edge[a][b]=edge[b][a]=c; } Dijkstra(n); printf("%d\n",dis[1]); } return 0;}
- POJ 2387 Til the Cows Come Home 最短路-Dijkstra
- POJ 2387 || Til the Cows Come Home(最短路,dijkstra
- poj Til the Cows Come Home (Dijkstra最短路~)
- POJ 2387 Til the Cows Come Home (最短路+Dijkstra)
- POJ 2387-Til the Cows Come Home(最短路Dijkstra+优先队列)
- poj 2387 Til the Cows Come Home(最短路SPFA+Dijkstra)
- POJ 2387 Til the Cows Come Home(最短路dijkstra)
- POJ - 2387 Til the Cows Come Home(最短路Dijkstra模板题)
- POJ-2387Til the Cows Come Home,最短路坑题,dijkstra+队列优化
- poj 2387 Til the Cows Come Home 最短路 dijkstra算法
- POJ 2387 Til the Cows Come Home 【最短路(dijkstra)】
- POJ 2387Til the Cows Come Home(最短路)
- poj 2387 Til the Cows Come Home(最短路)
- poj 2387 Til the Cows Come Home -- 最短路dijstra
- 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 (最短路)
- 数码知识扫盲:微单和单反到底有什么区别
- 在线客服交流系统部署和安装
- oracle设置自动增长列
- 如何通过adb shell 修改/显示 GPIO 状态
- Eclipse快捷键大全(转载)
- POJ 2387 Til the Cows Come Home 最短路-Dijkstra
- altium 怎样测量间距和尺寸
- 学习笔记00—Eclipse使用技巧
- Java处理日期常用方法
- 期货保证金 不足
- 宽字符
- JSTL——核心标签:
- 用C#创建Windows 服务
- Linux命令——tar命令详解