HdU 2544 最短路
2016-04-30 23:57
176 查看
明天更新spfa。。。
下面是djstl
下面是djstl
#include<cstdio> #include<cstring> #include<iostream> #include<queue> #include<vector> #include<string> using namespace std; struct sb { int x; int t; sb(int a,int b) { x=a; t=b; } bool operator<(const sb&wakaka)const { return t>wakaka.t; } }; vector<sb>bian[10010]; int n; int ts[10010]; int vis[10010]; void djstl(int who) { for(int i=1;i<=n;i++) { ts[i]=0x3f3f3f3f; vis[i]=0; } ts[who]=0; priority_queue<sb>q; q.push(sb(who,ts[who])); while(!q.empty()) { sb x=q.top(); q.pop(); if(vis[x.x]) { continue; } vis[x.x]=1; for(int i=0;i<bian[x.x].size();i++) { sb y=bian[x.x][i]; if(ts[y.x]>x.t+y.t) { ts[y.x]=x.t+y.t; q.push(sb(y.x,ts[y.x])); } } } } int main() { int m; while(cin>>n>>m) { if(n==0&&m==0) break; int a,b,t; for(int i=1;i<=m;i++) { cin>>a>>b>>t; bian[b].push_back(sb(a,t)); bian[a].push_back(sb(b,t)); } djstl(1); for(int i=1;i<=n;i++) { bian[i].clear(); } cout<<ts <<endl; } return 0; }
相关文章推荐
- 【HDU 5366】The mook jong 详解
- 【HDU 2136】Largest prime factor 详细图解
- 【HDU 1568】Fibonacci 数学公式 详解
- HDU 1568
- HDU1290
- HDU1568(Fobonacci公式)
- HDU ACM Step 2.2.2 Joseph(约瑟夫环问题)
- HDU 1405
- HDU 1297
- hdu 1205
- hdu 2087
- hdu 1016
- HDU 4898 The Revenge of the Princess’ Knight ( 2014 Multi-University Training Contest 4 )
- HDU 5592 ZYB's Premutation 线段树(查找动态区间第K大)
- HDU 5240 Exam (好水的题)
- HDU5237 Base64 大模拟
- HDU 1000
- HDU 1001
- HDU 1016 Prime Ring Problem
- HDU 1017 A Mathematical Curiosity