poj 2387 Til the Cows Come Home//最短路径
来源:互联网 发布:淘宝客服售前操作流程 编辑:程序博客网 时间:2024/05/22 00:23
求1到N的最短路径。用的spfa算法,注意重边问题。
#include<iostream>#include<stdio.h>#include<string.h>using namespace std;const int maxn = 1007;const int maxcost = 99999999;int n,t;int g[maxn][maxn],dist[maxn],vis[maxn];int queue[maxn*8],front,rear;void spfa(int sink,int source){int i,j,k;for(i=1;i<=n;i++){dist[i]=maxcost;vis[i]=0;}dist[sink]=0;vis[sink]=1;front=0,rear=0;queue[rear++]=sink;while(rear!=front){int temp= queue[front++];for(i=1;i<=n;i++)if(dist[i]>dist[temp]+g[temp][i]){dist[i]=dist[temp]+g[temp][i];if(!vis[i]){vis[i]=1;queue[rear++]=i;}}vis[temp]=0;}printf("%d\n",dist[source]);}int main(){int i,j;cin>>t>>n;for(i=1;i<=n;i++)for(j=1;j<=n;j++)g[i][j]=maxcost;for(i=0;i<t;i++){int a,b,c;scanf("%d %d %d",&a,&b,&c);g[a][b]=g[a][b]>c?c:g[a][b];g[b][a]=g[b][a]>c?c:g[b][a];}spfa(1,n);return 0;}
- poj 2387Til 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(Dijkstra 最短路径)
- POJ 2387 Til the Cows Come Home(最短路径,模板题)
- POJ 2387 Til the Cows Come Home(最短路径)
- POJ 2387 Til the Cows Come Home (最短路径,Dijkstra算法)
- Til the Cows Come Home(最短路径)
- POJ2387 Til the Cows Come Home(最短路径)
- Til the Cows Come Home 最短路径
- Til the Cows Come Home (最短路径)
- 最短路径_Til the Cows Come Home (Poj 2387)
- POJ 2387Til the Cows Come Home(最短单源路径)(dijkstra)
- POJ 2387Til the Cows Come Home(最短路)
- POJ 2387 Til the Cows Come Home 最短路-Dijkstra
- POJ 2387 || Til the Cows Come Home(最短路,dijkstra
- poj 2387 Til the Cows Come Home(最短路)
- mac lion svnserver搭建 笔记
- .net 后台创建简单的表格
- HibernateSessionFactory (MyEclipse自动生成版)
- MySQL的备份与恢复
- C语言和设计模式(抽象工厂模式)【文章都是来自网络,只要自己吸取了就是自己的】 .
- poj 2387 Til the Cows Come Home//最短路径
- Sed命令总汇
- C语言中字符串的\0和空格
- Linux Beyond Compare 3试用破解
- Oracle 游标使用全解
- 为什么c++不叫++c?
- LINUX RAC修改配置LOCK_SGA
- UISlider滑块控件的使用总结
- XHProf安装使用笔记