提交记录 5946


用户 题目 状态 得分 用时 内存 语言 代码长度
zjp_shadow noi18a. 【NOI2018】归程 Accepted 100 1.327 s 89796 KB C++11 3.75 KB
提交时间 评测时间
2018-09-13 16:49:40 2020-08-01 00:37:14
#include <bits/stdc++.h>

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__) 

using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

inline int read() {
    int x = 0, fh = 1; char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') fh = -1;
    for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ 48);
    return x * fh;
}

void File() {
    freopen ("return.in", "r", stdin);
    freopen ("return.out", "w", stdout);
}

int n, m;

const int N = 4e5 + 1e3, M = 8e5 + 1e3;

struct Edge {
    int u, v, a;

    inline bool operator < (const Edge &rhs) const {
        return a > rhs.a;
    }

} lt[N];

typedef pair<int, int> PII;
#define fir first
#define sec second
#define mp make_pair

namespace Dijsktra {

    int Head[N], Next[M], to[M], val[M], e = 0;

    void Init() { 
        Set(Head, 0); 
        e = 0; 
    }

    inline void add_edge(int u, int v, int w) { to[++ e] = v; Next[e] = Head[u]; val[e] = w; Head[u] = e; }

    priority_queue<PII, vector<PII>, greater<PII> > P; 
    bool vis[N]; int dis[N];
    void Run() {
        Set(vis, false);
        Set(dis, 0x7f); dis[1] = 0; P.push(mp(0, 1));
        while (!P.empty()) {
            PII cur = P.top(); int u = cur.sec; P.pop();
            if (vis[u]) continue ; 
            vis[u] = true;

            for (int i = Head[u]; i; i = Next[i]) {
                int v = to[i];
                if (chkmin(dis[v], dis[u] + val[i])) 
                    P.push(mp(dis[v], v));
            }
        }
    }

}

namespace Kruskal {

    int mina[20][N], mind[N], to[20][N], fa[N], Logn, num = 0;

    void Init(int *bas) {
        For (i, 1, n)
            fa[i] = i, mind[i] = bas[i]; num = n;
    }

    int find(int x) {
        return x == fa[x] ? x : fa[x] = find(fa[x]); 
    }

    inline int Min(int x, int y) {
        return x < y ? x : y;
    }

    void Build() {

        sort(lt + 1, lt + 1 + m);

        For (i, 1, m) {
            int x = lt[i].u, y = lt[i].v, alt = lt[i].a;

            int rtx = find(x), rty = find(y);
            if (rtx == rty) continue ;

            mind[++ num] = min(mind[rtx], mind[rty]);

            fa[num] = 
                to[0][rtx] = fa[rtx] = 
                to[0][rty] = fa[rty] = num;

            mina[0][rtx] = mina[0][rty] = alt;
        }

        Logn = ceil(log(num) / log(2));
        For (j, 1, Logn) For (i, 1, num) {
            to[j][i] = to[j - 1][to[j - 1][i]];
            mina[j][i] = Min(mina[j - 1][i], mina[j - 1][to[j - 1][i]]);
        }

    }

    inline int Query(int pos, int lim) {
        Fordown (i, Logn, 0)
            if (mina[i][pos] > lim) pos = to[i][pos];
        return mind[pos];
    }

}

int q, k, s;

int main () {

    int cases = read();
    while (cases --) {

        n = read(); m = read();

        Dijsktra :: Init();

        For (i, 1, m) {
            int u = read(), v = read(), l = read(), a = read();
            lt[i] = (Edge) {u, v, a};
            Dijsktra :: add_edge(u, v, l);
            Dijsktra :: add_edge(v, u, l);
        }
        Dijsktra :: Run();

        Kruskal :: Init(Dijsktra :: dis); Kruskal :: Build();

        q = read(); k = read(); s = read();
        int ans = 0;
        while (q --) {
            int v = (1ll * read() + k * ans - 1) % n + 1;
            int	p = (1ll * read() + k * ans) % (s + 1);

            printf ("%d\n", ans = Kruskal :: Query(v, p));
        }

    }

    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #1466.25 us3 MB + 504 KBAcceptedScore: 5

Testcase #2493.3 us3 MB + 556 KBAcceptedScore: 5

Testcase #3633.71 us3 MB + 600 KBAcceptedScore: 5

Testcase #4727.51 us3 MB + 616 KBAcceptedScore: 5

Testcase #53.627 ms4 MB + 104 KBAcceptedScore: 5

Testcase #6524.42 ms83 MB + 160 KBAcceptedScore: 5

Testcase #73.071 ms4 MB + 20 KBAcceptedScore: 5

Testcase #83.071 ms4 MB + 24 KBAcceptedScore: 5

Testcase #93.072 ms4 MB + 20 KBAcceptedScore: 5

Testcase #10515.317 ms77 MB + 144 KBAcceptedScore: 5

Testcase #11518.901 ms77 MB + 148 KBAcceptedScore: 5

Testcase #12694.543 ms84 MB + 776 KBAcceptedScore: 5

Testcase #13694.08 ms84 MB + 612 KBAcceptedScore: 5

Testcase #14693.803 ms84 MB + 20 KBAcceptedScore: 5

Testcase #154.312 ms4 MB + 108 KBAcceptedScore: 5

Testcase #164.31 ms4 MB + 112 KBAcceptedScore: 5

Testcase #17694.644 ms84 MB + 288 KBAcceptedScore: 5

Testcase #18693.391 ms84 MB + 576 KBAcceptedScore: 5

Testcase #191.326 s87 MB + 708 KBAcceptedScore: 5

Testcase #201.327 s87 MB + 208 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2024-12-05 10:34:51 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠