• 2018 ICPC Asia Nanjing Regional Preliminary L. Magical Girl Haze


    传送门

    #include <bits/stdc++.h>
    
    using namespace std;
    using ll = long long;
    using p = pair<ll, int>;
    const double pi(acos(-1));
    const int maxn(1e7 + 10);
    const int maxm(1e7 + 10);
    int ecnt, head[maxn];
    bool vis[maxn];
    ll 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);
    }
    
    inline void addEdge(int u, int v, int w)
    {
        edges[ecnt].to = v;
        edges[ecnt].wt = w;
        edges[ecnt].nxt = head[u];
        head[u] = ecnt++;
    }
    
    ll 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
        int t = read();
        while (t--) {
            ecnt = 0;
            memset(head, -1, sizeof head);
            memset(vis, false, sizeof vis);
            memset(dis, 0x3f, sizeof dis);
            int n = read(), m = read(), k = read();
            while (m--) {
                int u = read(), v = read(), w = read();
                addEdge(u, v, w);
                for (int i = 0; i < k; ++i) {
                    addEdge(u + i * n, v + (i + 1) * n, 0);
                    addEdge(u + (i + 1) * n, v + (i + 1) * n, w);
                }
            }
            for (int i = 1; i <= k; ++i) {
                addEdge(n * i, n + (i + 1), 0);
            }
            write(dijkstra(1, n, k, n), true);
        }
        return 0;
    }
    
  • 相关阅读:
    apk反编译
    Eclipse Android项目中如如第三方library文件
    layout_gravity属性和gravity属性区别(转载)
    android weight 属性正解(转载)
    010_01Servlet Request&Response
    009_02sendRedirect() forward() include()
    009_01Servlet基础简介
    008_02HTTP基础知识
    008_01WEB基础知识
    【实用】让代码变的更加简洁
  • 原文地址:https://www.cnblogs.com/singularity2u/p/14032697.html
Copyright © 2020-2023  润新知