【链接】http://acm.hdu.edu.cn/showproblem.php?pid=6181


【题意】


让你求从1到n的次短路

【题解】


模板题;
因为点可以重复走;
则一定会有次短路。
dijkstra算法+优先队列优化一下就好.

【错的次数】


11+

【反思】


在写优先队列的时候,节点和路径长度写反了..应该节点写在后面才行的。。

【代码】

#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的更多相关文章

  1. 【数位dp】【HDU 3555】【HDU 2089】数位DP入门题

    [HDU  3555]原题直通车: 代码: // 31MS 900K 909 B G++ #include<iostream> #include<cstdio> #includ ...

  2. 【HDU 5647】DZY Loves Connecting(树DP)

    pid=5647">[HDU 5647]DZY Loves Connecting(树DP) DZY Loves Connecting Time Limit: 4000/2000 MS ...

  3. -【线性基】【BZOJ 2460】【BZOJ 2115】【HDU 3949】

    [把三道我做过的线性基题目放在一起总结一下,代码都挺简单,主要就是贪心思想和异或的高斯消元] [然后把网上的讲解归纳一下] 1.线性基: 若干数的线性基是一组数a1,a2,a3...an,其中ax的最 ...

  4. 【HDU 2196】 Computer(树的直径)

    [HDU 2196] Computer(树的直径) 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 这题可以用树形DP解决,自然也可以用最直观的方法解 ...

  5. 【HDU 2196】 Computer (树形DP)

    [HDU 2196] Computer 题链http://acm.hdu.edu.cn/showproblem.php?pid=2196 刘汝佳<算法竞赛入门经典>P282页留下了这个问题 ...

  6. 【HDU 5145】 NPY and girls(组合+莫队)

    pid=5145">[HDU 5145] NPY and girls(组合+莫队) NPY and girls Time Limit: 8000/4000 MS (Java/Other ...

  7. 【hdu 1043】Eight

    [题目链接]:http://acm.hdu.edu.cn/showproblem.php?pid=1043 [题意] 会给你很多组数据; 让你输出这组数据到目标状态的具体步骤; [题解] 从12345 ...

  8. 【HDU 3068】 最长回文

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=3068 [算法] Manacher算法求最长回文子串 [代码] #include<bits/s ...

  9. 【HDU 4699】 Editor

    [题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=4699 [算法] 维护两个栈,一个栈放光标之前的数,另外一个放光标之后的数 在维护栈的同时求最大前缀 ...

随机推荐

  1. Android入门篇(一)Androidproject的搭建,导入与导出,图标的改动

       先说一些题外话吧.这是小珂同学的处女作.可能写的不好,请各位读者见谅.我先讲讲我为什么要写博文,那应该也是机缘巧合,有一次.我问学长一个问题,学长发了一个连接给我,里面是一篇博客.那时我仅仅是看 ...

  2. 如何批量ping地址查看网络是否畅通

    测试环境搬迁后,需要批量去ping所有机器的IP,看网络是否畅通 测试思路: [weblogic@pays03pre_BankVerify luyantest]$ ping -c 1 172.29.1 ...

  3. 本地用户 vsftpd 配置文件

    # 禁止匿名用户anonymous登录 anonymous_enable=NO # 允许本地用户登录 local_enable=YES local_root=/data/wwwroot/ # 让登录的 ...

  4. 【Uva 10723】Cyborg Genes

    [Link]: [Description] 给你两个串s1,s2; 让你生成一个串S; 使得s1和s2都是S的子列; 要求S最短; 求S的不同方案个数; [Solution] 设两个串的长度分别为n1 ...

  5. window 搭建python环境

    Unofficial Windows Binaries for Python Extension Packages 其中包含大量Windows下的python的module 包含大但不仅限于pip: ...

  6. Extjs 4.2 设置buttontext为中文

    能够在Ext.QuickTips.init();后增加例如以下代码: Ext.MessageBox.buttonText = { ok : "确定", cancel : " ...

  7. P2P进入整顿期,平衡风险和收益之间的矛盾是关键

        毫无疑问,P2P网贷进入了其诞生以来最为关键的整顿期,随着大量提现困难.跑路的P2P平台被曝光之后.行业对P2P网贷的发展也多了几分慎重.少了几分浮躁.只是,P2P网贷所面临的问题正是其它不论 ...

  8. IsoAlgo3d - IDF/PCF pipeline 3d viewer

    IsoAlgo3d - IDF/PCF pipeline 3d viewer eryar@163.com Key Words. IDF, PCF, IsoAlgo, 3D 当前国际主流管道设计软件都可 ...

  9. 搭建个人博客 方式2 使用jekyll

    孙广东  2016.3.12 环境安装:1.通过 RailsInstaller  来安装 Ruby https://www.ruby-lang.org/zh_cn/documentation/inst ...

  10. jQuery07源码 (3803 , 4299) attr() prop() val() addClass()等 : 对元素属性的操作

    var nodeHook, boolHook, rclass = /[\t\r\n\f]/g, rreturn = /\r/g, rfocusable = /^(?:input|select|text ...