CCF-交通规划
来源:互联网 发布:手机透镜桌面软件 编辑:程序博客网 时间:2024/04/29 11:00
#include<cstdio>#include<queue>#include<vector>#define maxn 100005#define inf 0x7fffffff int n,m;using namespace std;struct Point{ int u; int dist; Point(int uu,int d){ u=uu,dist=d; } friend bool operator < (Point a,Point b) { return a.dist > b.dist; }};struct Edge{ int v; int cost; Edge(int vv,int c){ v=vv,cost=c; }};vector<Edge> G[maxn];bool vis[maxn];int disto[maxn];int costo[maxn];void Dijkstra(int s){ for(int i=1;i<=n;i++){ vis[i]=false; disto[i]=costo[i]=inf; } disto[s]=0; costo[s]=0; priority_queue<Point> queue; queue.push(Point(s,0)); while(!queue.empty()){ Point p=queue.top(); queue.pop(); int u=p.u; if(!vis[u]){ for(int i=0;i<G[u].size();i++){ int v=G[u][i].v; int co=G[u][i].cost; if(!vis[v]){ if(disto[v]>disto[u]+co){ disto[v]=disto[u]+co; queue.push(Point(v,disto[v])); costo[v]=co; } if(disto[v]==disto[u]+co){ costo[v]=min(costo[v],co); } } } } }}int main(){ int u,v,c; scanf("%d%d",&n,&m); while(m--){ scanf("%d%d%d",&u,&v,&c); G[u].push_back(Edge(v,c)); G[v].push_back(Edge(u,c)); } Dijkstra(1); int ans=0; for(int i=2;i<=n;i++) ans+=costo[i]; printf("%d",ans);}
0 0
- CCF-交通规划
- CCF交通规划
- CCF 交通规划
- ccf 交通规划
- ccf交通规划
- CCF交通规划
- CCF 交通规划
- ccf 交通规划
- CCF-20160904-交通规划
- ccf 交通规划
- CCF 201612-4 交通规划
- CCF 201609-4 交通规划
- CCF 201612-4 交通规划
- 第八次ccf-交通规划
- CCF-交通规划-dijkstra+贪心
- ccf 201609-4交通规划
- ccf 之交通规划 java版
- CCF 201612-4 交通规划(spfa)
- xdoj-1003
- 447. Number of Boomerangs
- 使用Hexo搭建个人博客(一)
- 数据库表命名规范
- 第二课(MySQL基础知识)
- CCF-交通规划
- 浅拷贝,深拷贝,简洁版的深拷贝,浅拷贝的优化版(引用计数)
- Activity实现无动画跳转
- 使用Hexo搭建个人博客(二)
- a*自动寻路算法详解
- UVA392 模拟(多项式输出),水
- test 11-9 [水题 树链剖分 差分]
- 用最专业的态度解决最小问题
- JavaScript学习笔记1----类型、值和变量