【hdu 6181】Two Paths
【链接】http://acm.hdu.edu.cn/showproblem.php?pid=6181
【题意】
【题解】
【错的次数】
【反思】
【代码】
#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb emplace_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)
#define sz(x) ((int) x.size()) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; mt19937 myrand(time(0));
int get_rand(int n){return myrand()%n + 1;}
const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;
const LL INF = 0x3f3f3f3f3f3f3f3f; struct abc{
int en,nex;
LL w;
}; int n,m;
LL dis[N+10][2];
priority_queue <pll ,vector <pll> ,greater<pll> > dl;
vector <pii> G[N+10]; int main(){
//Open();
//Close();
int T;
ri(T);
while (T--){
ri(n),ri(m);
rep1(i,1,n) G[i].clear();
rep1(i,1,m){
int a,b; LL w;
ri(a),ri(b),rl(w);
G[a].pb(mp(b,w));
G[b].pb(mp(a,w));
}
ms(dis,INF);
dis[1][0] = 0;
dl.push(mp(0,1));
while (!dl.empty()){
LL d = dl.top().fi,x = dl.top().se;
dl.pop();
if (dis[x][1] < d) continue;
int len = sz(G[x]);
rep1(i,0,len-1){
LL y = G[x][i].fi,cost = d + G[x][i].se;
if (dis[y][0] > cost){
dis[y][1] = dis[y][0];
dis[y][0] = cost;
dl.push(mp(dis[y][0],y));
}
else if (dis[y][1] > cost){
dis[y][1] = cost;
dl.push(mp(dis[y][1],y));
}
}
}
ol(dis[n][1]);puts("");
}
return 0;
}
【hdu 6181】Two Paths的更多相关文章
- 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题
[HDU 3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...
- 【HDU 5647】DZY Loves Connecting(树DP)
pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...
- -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】
[把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...
- 【HDU 2196】 Computer(树的直径)
[HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...
- 【HDU 2196】 Computer (树形DP)
[HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...
- 【HDU 5145】 NPY and girls(组合+莫队)
pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...
- 【hdu 1043】Eight
[题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...
- 【HDU 3068】 最长回文
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...
- 【HDU 4699】 Editor
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...
随机推荐
- Sqoop Import原理和详细流程讲解
Sqoop Import原理 Sqoop Import详细流程讲解 Sqoop在import时,需要指定split-by参数.Sqoop根据不同的split-by参数值来进行切分,然后将切分出来的区域 ...
- java引用被设置为null的疑惑
a=null; public class C { protected A webDigester = new A(" first one "); public void test( ...
- SQL函数-str()
1 str()函数用于将数值类型数据转换未字符类型. 2 str()函数语法 select str(数字类型的表达式[,表达式总长度][,小数点后面的位数]) 表达式总长度和小数点后面的位数为可选择参 ...
- Linux常用Office办公软件
1.WPS Office是由金山软件股份有限公司自主研发的一款办公软件套件,可以实现办公最常用的文字.表格.演示等多种功能.免费提供海量的在线存储空间及文档模板.支持阅读和输出PDF文件.全面兼容Mi ...
- shell中IF的用法介绍
一.语法结构 if [ condition ] then statements [elif condition then statements. ..] [else ...
- centos 7 mongodb4.0 安装配置
1.下载安装 cat <<EOF> /etc/yum.repos.d/mongodb-org-4.0.repo [mongodb-org-4.0]name=MongoDB Repos ...
- 【Henu ACM Round #13 D】A Trivial Problem
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 123...n中末尾0的个数 只会由素因子2和5的个数决定且等于 Min{cnt[2],cnt[5]} 且素因子2的个数一定会比5多 ...
- HRBUST 1818 石子合并问题--直线版
石子合并问题--直线版 Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on HRBUST. Original ...
- cogs 32. [POI1999] 位图
32. [POI1999] 位图 ★ 输入文件:bit.in 输出文件:bit.out 简单对比时间限制:1 s 内存限制:128 MB [问题描述 ] 给定一个 n*m 的矩形位图, ...
- 网络最大流算法—Dinic算法及优化
前置知识 网络最大流入门 前言 Dinic在信息学奥赛中是一种最常用的求网络最大流的算法. 它凭借着思路直观,代码难度小,性能优越等优势,深受广大oier青睐 思想 $Dinic$算法属于增广路算法. ...