• 洛谷 P4568 [JLOI2011]飞行路线


    传送门

    #include <bits/stdc++.h>
    
    using namespace std;
    using ll = long long;
    using p = pair<int, int>;
    const double pi(acos(-1));
    const int inf(0x3f3f3f3f);
    const int mod(1e9 + 7);
    const int maxn(2e5 + 10);
    const int maxm(3e6 + 10);
    int ecnt, head[maxn];
    bool vis[maxn];
    int dis[maxn];
    
    struct edge {
        int to, wt, nxt;
    } edges[maxm];
    
    template<typename T = int>
    inline const T read()
    {
        T x = 0, f = 1;
        char ch = getchar();
        while (ch < '0' || ch > '9') {
            if (ch == '-') f = -1;
            ch = getchar();
        }
        while (ch >= '0' && ch <= '9') {
            x = (x << 3) + (x << 1) + ch - '0';
            ch = getchar();
        }
        return x * f;
    }
    
    template<typename T>
    inline void write(T x, bool ln)
    {
        if (x < 0) {
            putchar('-');
            x = -x;
        }
        if (x > 9) write(x / 10, false);
        putchar(x % 10 + '0');
        if (ln) putchar(10);
    }
    
    void addEdge(int u, int v, int w, bool d)
    {
        edges[ecnt].to = v;
        edges[ecnt].wt = w;
        edges[ecnt].nxt = head[u];
        head[u] = ecnt++;
        if (d) addEdge(v, u, w, false);
    }
    
    int dijkstra(int src, int des, int k, int n)
    {
        priority_queue<p, vector<p>, greater<p>> q;
        q.push(p(0, src));
        dis[src] = 0;
        while (not q.empty()) {
            int u = q.top().second;
            q.pop();
            if (vis[u]) continue;
            vis[u] = true;
            for (int i = head[u]; compl i; i = edges[i].nxt) {
                int v = edges[i].to, w = edges[i].wt;
                if (dis[v] > dis[u] + w) {
                    dis[v] = dis[u] + w;
                    q.push(p(dis[v], v));
                }
            }
        }
        return dis[des + k * n];
    }
    
    int main()
    {
    #ifdef ONLINE_JUDGE
    #else
        freopen("input.txt", "r", stdin);
    #endif
        memset(head, -1, sizeof head);
        memset(dis, 0x3f, sizeof dis);
        int n = read(), m = read(), k = read();
        int s = read(), t = read();
        while (m--) {
            int u = read(), v = read(), w = read();
            addEdge(u, v, w, true);
            for (int i = 0; i < k; ++i) {
                addEdge(u + i * n, v + (i + 1) * n, 0, false);
                addEdge(v + i * n, u + (i + 1) * n, 0, false);
                addEdge(u + (i + 1) * n, v + (i + 1) * n, w, true);
            }
        }
        for (int i = 0; i < k; ++i) {
            addEdge(t + i * n, t + (i + 1) * n, 0, false);
        }
        write(dijkstra(s, t, k, n), true);
        return 0;
    }
    
  • 相关阅读:
    angular 复选框回选
    $parse
    AngularJS 指令的 Scope (作用域)
    文献解读 (1)
    献给初学者:常用的细胞凋亡检测方法
    KofamKOALA
    Dfam.h5.gz下载
    Augustus-3.3.3安装
    bamtools 2.5.1安装
    R语言从原点开始作图
  • 原文地址:https://www.cnblogs.com/singularity2u/p/14032720.html
Copyright © 2020-2023  润新知