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. $x^2+y^2=c^2$

    $x^2+y^2=c^2$ 每一个实数都能用有理数去逼近到任意精确的程度,这就是有理数的稠密性.The rational points are dense on the number axis. 每一 ...

  2. js中避免函数名和变量名跟别人冲突

    待补充 .... 参考链接: http://blog.csdn.net/formyqianduan/article/details/52118690

  3. SimpleDateFormat使用详解——日期、字符串应用

    public class SimpleDateFormat extends DateFormat SimpleDateFormat 是一个以国别敏感的方式格式化和分析数据的具体类. 它允许格式化 (d ...

  4. .Net Core Linux centos7行—IOC模块

    .net core中可以说是用了全新的IOC模板,定义在Microsoft.Extensions.DependencyInjection下.提供了一套标准的接口.并提供了默认实现.并且大范围使用着,处 ...

  5. GreenDao的使用

    1.生成代码文件

  6. postgresql 导入sql,out等sql文件

    假设postgresql安装位置 然后,使用dos窗口进入这个位置 导入(本地和默认端口可以不用属性) psql -d 数据库名 -h ip地址 -p 数据库端口 -U 用户名 -f 文件地址 完成

  7. C语言猜数字游戏

    猜数字游戏,各式各样的实现方式,我这边提供一个实现方式,希望可以帮到新手. 老程序猿就不要看了,黑呵呵 源代码1 include stdio.h include stdlib.h include ti ...

  8. jsp上传图片实时显示

    jsp代码 <div class="form-group" id="caseIma"> <label class="control- ...

  9. django 关于html、css、js 目录位置

    项目目录: project/ ---------------init.py ---------------views.py ---------------settings.py ----------- ...

  10. 如何生成每秒百万级别的 HTTP 请求?

    第一篇:<如何生成每秒百万级别的 HTTP 请求?> 第二篇:<为最佳性能调优 Nginx> 第三篇:<用 LVS 搭建一个负载均衡集群> 本文是构建能够每秒处理 ...