poj2387 Til the Cows Come Home
来源:互联网 发布:网络语ko是什么意思 编辑:程序博客网 时间:2024/05/18 03:06
最短路模板题,套用模板就行。
#include<stdio.h>#include<stdlib.h>int b[1100],dis[1100],e[1100][1100];int main(){ int m,n,t1,t2,t3,i,j,v,u,min; int inf=99999999; while(~scanf("%d%d",&m,&n)) { for(i=1; i<=n; i++) for(j=1; j<=n; j++) if(i==j) e[i][j]=0; else e[i][j]=inf; for(i=1;i<=m;i++) { scanf("%d%d%d",&t1,&t2,&t3); if(e[t1][t2]>t3)//一定不能省略这个条件 e[t1][t2]=e[t2][t1]=t3;//无向图 } for(i=1;i<=n;i++) { dis[i]=e[1][i]; b[i]=0; } b[1]=1; for(i=1;i<n;i++) { min=inf; for(j=1;j<=n;j++) { if(b[j]==0&&dis[j]<min) { min=dis[j]; u=j; } } b[u]=1; for(v=1;v<=n;v++) { if(b[v]==0&&e[u][v]<inf&&dis[v]>dis[u]+e[u][v]) dis[v]=dis[u]+e[u][v]; } } printf("%d\n",dis[n]); } 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
- jasperReport和JasperServer的使用实例
- struts基本结构
- Hive入门--3.UDF编写与使用
- 每日安全简讯20160721
- HDU5289
- poj2387 Til the Cows Come Home
- eclipse自动提示功能没了的解决办法
- remove javascript validation from eclipse project
- CodeForces 580B Kefa and Company
- java类加载过程详解
- php响应超时
- Android EditText限制输入字符类型的几种方式
- TCP/IP协议族
- JVM 之 GC日志分析