POJ 2387
来源:互联网 发布:swift 自定义元素数组 编辑:程序博客网 时间:2024/05/20 20:19
求最短路,套模板即可~
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define inf 0x7ffffffint w[1005][1005],v[1005],d[1005];int t,n;int dijkstra(int s){ int p,minn; memset(v,0,sizeof(v)); for(int i=1;i<=n;i++) d[i]=inf; d[s]=0; for(int i=1;i<=n;i++) { minn=inf; for(int j=1;j<=n;j++) if(!v[j]&&d[j]<minn) { p=j; minn=d[j]; } v[p]=1; for(int j=1;j<=n;j++) { //cout<<p<<endl; if(!v[j]) d[j]=min(d[j],d[p]+w[p][j]); } } return d[n];}int main(){ while(scanf("%d%d",&t,&n)!=EOF) { for(int i=1;i<=n;i++)for(int j=1;j<=n;j++) w[i][j]=inf; while(t--) { int x,y,z; scanf("%d%d%d",&x,&y,&z); w[x][y]=min(w[x][y],z); //考虑重边的情况 w[y][x]=w[x][y]; } int ans=dijkstra(1); printf("%d\n",ans); } return 0;}
0 0
- POJ 2387
- POJ 2387
- poj 2387
- POJ 2387
- poj 2387
- poj 2387
- POJ 2387
- poj 2387
- poj--2387
- poj 2387
- POJ 2387
- poj 2387
- POJ 2387
- poj 2387
- POJ-2387
- POJ 2387
- poj 2387 dijkstra
- POJ 2387 dijkstra水题
- cocos2dx自学之路 精灵执行动作+TableView控件
- 4.第三单元任务三实训:编写一个类ExceptionTest,在main方法中使用try-catch-finally语句结构实现:在try语句块中,编写两个数相除操作,相除的两个操作数要求程序运行时用
- iOS中几种数据持久化方案
- java动态代理
- ohasd failed to start错误解决办法
- POJ 2387
- 2015年6月积累
- 12天学好C语言——记录我的C语言学习之路(Day 11)
- 什么叫编译时和运行时
- OC05_数组
- java.lang.IllegalStateException: Failure saving state: active HomeMainFg{42ed2fb8} has cleared index
- 5.编写一个java程序,该程序有两个类:Tank(用于刻画坦克)和Fight(主类)。 已知坦克类如下:
- Ubuntu系统常用操作指令说明
- 那个青春