COGS 826. [Tyvj Feb11] GF打dota (K短路)
来源:互联网 发布:淘宝兼职群 编辑:程序博客网 时间:2024/05/04 14:50
题目描述
传送门
题解
K短路板子题
代码
#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>#include<queue>#define N 100003#define inf 1000000000using namespace std;struct data{ int g,h,x; bool operator<(data const &a)const { return g+h>a.g+a.h; }};int point[N],len[N],v[N],nxt[N],dis[N],tot,n,m,can[N],ans,opt;void add(int x,int y,int z){ tot++; nxt[tot]=point[x]; point[x]=tot; v[tot]=y; len[tot]=z; tot++; nxt[tot]=point[y]; point[y]=tot; v[tot]=x; len[tot]=z;}void spfa(){ for (int i=1;i<=n;i++) dis[i]=inf; dis[n]=0; can[n]=1; queue<int> p; p.push(n); while (!p.empty()) { int now=p.front(); p.pop(); for (int i=point[now];i;i=nxt[i]) if (dis[v[i]]>dis[now]+len[i]) { dis[v[i]]=dis[now]+len[i]; if (!can[v[i]]) { can[v[i]]=1; p.push(v[i]); } } can[now]=0; }}void Astar(){ priority_queue<data> p; data a,nt; a.x=1; a.g=0; a.h=dis[1]; p.push(a); while (!p.empty()) { data now=p.top(); p.pop(); if (now.x==n&&now.g!=ans) { ans=now.g; return; } for (int i=point[now.x];i;i=nxt[i]){ nt.x=v[i]; nt.g=now.g+len[i]; nt.h=dis[v[i]]; p.push(nt); } }}int main(){ freopen("dota.in","r",stdin); freopen("dota.out","w",stdout); scanf("%d%d",&n,&m); for (int i=1;i<=m;i++) { int x,y,z; scanf("%d%d%d",&x,&y,&z); add(x,y,z); } spfa(); scanf("%d",&opt); if (opt==0) printf("%d\n",dis[1]); else{ ans=dis[1]; Astar(); printf("%d\n",ans); }}
0 0
- COGS 826. [Tyvj Feb11] GF打dota (K短路)
- [COGS826][Tyvj Feb11] GF打dota(k短路)
- COGS 133. [USACO Mar08] 牛跑步 (K短路)
- TYVJ P1013 找啊找啊找GF
- tyvj P1013 - 找啊找啊找GF
- Tyvj P1013 找啊找啊找GF
- TYVJ 1013 找啊找啊找GF题解
- 第K极值(Tyvj)
- 打dota的惩罚
- tyvj 1013 找啊找啊找GF
- COGS 498 TYVJ 1094 矩形分割 贪心
- tyvj 1505 打砖头
- TYVJ-1031 最短路
- 【Tyvj】第k极值
- GF(01)
- gf
- GF
- gf
- [bzoj3246] [Ioi2013]Dreaming
- “字符型减'0'可以得到整数型”的原因分析
- 深度学习真的万能吗?理解深度学习的局限性
- 计算机视觉CV 圈子
- springmvc文件上传与表单为enctype="multipart/form-data" 的数据绑定
- COGS 826. [Tyvj Feb11] GF打dota (K短路)
- SQL Server 2005 导出 数据脚本
- STM32F10x下载口的用法
- lintcode(76)最长上升子序列
- Spark性能优化指南——高级篇
- 【jzoj5042】【最小直径】【树形动态规划】【贪心/结论】
- 1042. 字符统计(20)
- C#里partial关键字的作用
- STL适配器之stack