Til the Cows Come Home POJ - 2387 dijkstra
2018-02-06 12:16
309 查看
才学习了dijkstra
这个是可以从a到b可以有多个边,而且还是双向的。输入的时候稍微修改一下就可以
http://blog.51cto.com/ahalei/1387799
上面的dijkstra讲的非常好QAQ5分钟学会floyd和dijkstra系列
后面的优化还没看。。有空去看。。。
emmm比较简单的题。。好像没什么变化
然后就是,i和j刚开始写一写混了。。。。
这个是可以从a到b可以有多个边,而且还是双向的。输入的时候稍微修改一下就可以
http://blog.51cto.com/ahalei/1387799
上面的dijkstra讲的非常好QAQ5分钟学会floyd和dijkstra系列
后面的优化还没看。。有空去看。。。
emmm比较简单的题。。好像没什么变化
然后就是,i和j刚开始写一写混了。。。。
#include<stdio.h> #include<string.h> #define INF 0x3f3f3f int book[1005],dis[1005],e[1003][1003]; int main() { int n,t,t1,t2,t3,min,u; while(scanf("%d%d",&t,&n)!=EOF) { for(int i=1;i<=1000;i++) for(int j=1;j<=1000;j++) { if(i==j) e[i][j]=0; else e[i][j]=INF; } memset(book,0,sizeof(book)); memset(dis,0,sizeof(dis)); for(int i=1;i<=t;i++) { scanf("%d%d%d",&t1,&t2,&t3); if(e[t1][t2]>t3 && e[t1][t2]>t3) {e[t1][t2]=t3;e[t2][t1]=t3;} } for(int i=1;i<=n;i++) dis[i]=e[1][i]; book[1]=1; for(int i=1;i<n;i++) { min=INF; for(int j=1;j<=n;j++) { if(book[j]==0 && dis[j]<min) { min=dis[j]; u=j; } } book[u]=1; for(int j=1;j<=n;j++) { if(book[j]==0 && e[u][j]<INF) { if(dis[j]>dis[u]+e[u][j]) dis[j]=dis[u]+e[u][j]; } } } // min=INF; //for(int i=2;i<=n;i++) //if(dis[i]<min) min=dis[i]; printf("%d\n",dis ); } }
相关文章推荐
- poj-2387 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 (Bellman_Ford || Dijkstra || SPFA)
- 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
- 2387 poj Til the Cows Come Home【dijkstra,经典&&基础】
- poj 2387 Til the Cows Come Home dijkstra
- POJ - 2387 Til the Cows Come Home(Dijkstra SPFA 邻接矩阵 邻接表)
- POJ 2387 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——dijkstra
- poj 2387 Til the Cows Come Home(dijkstra)
- POJ 2387 Til the Cows Come Home(最短路 Dijkstra/spfa)
- poj 2387 Til the Cows Come Home(Dijkstra)
- POJ 2387-Til the Cows Come Home(最短路Dijkstra+优先队列)