1、题意:dijkstra模板题,存点模板

#include <queue>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
#define M 2000010
#define inf 1047483647

inline int read(){
    char ch = getchar(); int x = 0, f = 1;
    while(ch < '0' || ch > '9'){
        if(ch == '-') f = -1;
        ch = getchar();
    }
    while('0' <= ch && ch <= '9'){
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}

namespace dijkstra{
    struct Node{
        int d, u;
        inline bool operator < (const Node& rhs) const{
            return d > rhs.d;
        }
    };
    int d[M], done[M];
    priority_queue<Node> Q;
    struct Edge{
        int u, v, w, next;
    } G[M];
    int head[M], tot;
    int n; //number of points

    inline void init(){
        memset(head, -1, sizeof(head));
        tot = -1;
    }

    inline void add(int u, int v, int w){
        G[++ tot] = (Edge){u, v, w, head[u]};
        head[u] = tot;
    }

    inline void get_dis(int s){
        for(int i = 1; i <= n; i ++) d[i] = inf;
        d[s] = 0; while(!Q.empty()) Q.pop();
        Q.push((Node){0, s});
        memset(done, 0, sizeof(done));
        while(!Q.empty()){
            Node u = Q.top(); Q.pop();
            int x = u.u;
            if(done[x]) continue;
            done[x] = 1;
            for(int i = head[x]; i != -1; i = G[i].next){
                Edge& e = G[i];
                if(d[e.v] > d[x] + e.w){
                    d[e.v] = d[x] + e.w;
                    Q.push((Node){d[e.v], e.v});
                }
            }
        }
    }
}

using namespace dijkstra;

int main(){
    n = read();
    int m = read();
    init();
    for(int i = 1; i <= m; i ++){
        int u = read(), v = read(), w = read();
        add(u, v, w);
    }
    get_dis(1);
    printf("%d\n", d[n]);
    return 0;
}

BZOJ2292——【POJ Challenge 】永远挑战的更多相关文章

  1. bzoj2292【POJ Challenge 】永远挑战*

    bzoj2292[POJ Challenge ]永远挑战 题意: 有向图,每条边长度为1或2,求1到n最短路.点数≤100000,边数≤1000000. 题解: 有人说spfa会T,所以我用了dijk ...

  2. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

  3. 2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 553  Solved: 230[Submit][ ...

  4. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  5. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  6. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  7. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  8. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  9. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  10. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

随机推荐

  1. jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.

    jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...

  2. 客户端Socket

    导语 java.net.Socket类是JAVA完成客户端TCP操作的基础类.其他建立TCP网络连接的类(如URL,URLConnection和EditorPane)最终会调用这个类的方法.这个类本身 ...

  3. 【BZOJ 1061】【Vijos 1825】【NOI 2008】志愿者招募

    http://www.lydsy.com/JudgeOnline/problem.php?id=1061 https://vijos.org/p/1825 直接上姜爷论文... #include< ...

  4. jquery-读取form表单中的所有数据列表

    代码: <script> $(function() { $('#submit').click(function() { var d = {}; var t = $('form').seri ...

  5. 基于MemoryCache的缓存辅助类

    背景: 1. 什么是MemoryCache? memoryCache就是用电脑内存做缓存处理 2.使用范围? 可用于不常变的数据,进行保存在内存中,提高处理效率 代码: /// <summary ...

  6. (转)gulp使用

    前端构建工具gulpjs的使用介绍及技巧 gulpjs是一个前端构建工具,与gruntjs相比,gulpjs无需写一大堆繁杂的配置参数,API也非常简单,学习起来很容易,而且gulpjs使用的是nod ...

  7. jQuery中json对象与json字符串互换

    json字符串转json对象:jQuery.parseJSON(jsonStr); json对象转json字符串:JSON.stringify(jsonObj); 根据“|”把字符串变成数组.spli ...

  8. Codeforces 710F String Set Quries

    题意 维护一个字符串的集合\(D\), 支持3种操作: 插入一个字符串\(s\) 删除一个字符串\(s\) 查询一个字符串\(s\)在\(D\)中作为子串出现的次数 强制在线 解法 AC自动机+二进制 ...

  9. Linux 文件压缩与归档

    .note-content { font-family: "Helvetica Neue", Arial, "Hiragino Sans GB", STHeit ...

  10. UITextField的placeholder文字的位置,颜色等的自定义设置

    //控制placeHolder的位置,左右缩20 -(CGRect)placeholderRectForBounds:(CGRect)bounds { CGRect inset = CGRectMak ...