提交记录 4327


用户 题目 状态 得分 用时 内存 语言 代码长度
larryzhong noi18a. 【NOI2018】归程 Accepted 100 1.939 s 170116 KB C++ 2.83 KB
提交时间 评测时间
2018-07-19 20:57:17 2020-07-31 22:52:59
#include <bits/stdc++.h>
using namespace std;

const int maxn = 600010;
int T, n, m, q, K, S, c, lastans, dist[maxn], fa[maxn];
int dep[maxn], par[maxn][21], mn[maxn][21];
bool vis[maxn];
struct edge {
    int to, l, a;
    bool operator < (const edge &other) const { return l > other.l; }
};
vector<edge> G[maxn], G2[maxn];
struct node {
    int u, v, l, a;
    bool operator < (const node &other) const { return a > other.a; }
} e[maxn];

void dijkstra() {
    priority_queue<edge> q;
    memset(dist, 0x3f, sizeof(dist));
    q.push((edge){1, 0, 0}), dist[1] = 0;
    while (!q.empty()) {
        edge v = q.top(); q.pop();
        for (int i = 0; i < G[v.to].size(); i++) {
            if (dist[G[v.to][i].to] > dist[v.to] + G[v.to][i].l) {
                dist[G[v.to][i].to] = dist[v.to] + G[v.to][i].l;
                q.push((edge){G[v.to][i].to, dist[G[v.to][i].to], 0});
            }
        }
    }
}

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

void dfs(int v, int f) {
    for (int i = 1; (1 << i) <= c; i++) {
        par[v][i] = par[par[v][i - 1]][i - 1];
    }
    for (int i = 1; (1 << i) <= c; i++) {
        mn[v][i] = min(mn[v][i - 1], mn[par[v][i - 1]][i - 1]);
    }
    for (int i = 0; i < G2[v].size(); i++) {
        if (G2[v][i].to == f) continue;
        par[G2[v][i].to][0] = v, mn[G2[v][i].to][0] = G2[v][i].a;
        dep[G2[v][i].to] = dep[v] + 1;
        dfs(G2[v][i].to, v);
        dist[v] = min(dist[v], dist[G2[v][i].to]);
    }
}

int main() {
    scanf("%d", &T);
    while (T--) {
        scanf("%d %d", &n, &m);
        for (int i = 1; i <= (n << 3); i++) G[i].clear(), G2[i].clear();
        for (int i = 1, u, v, l, a; i <= m; i++) {
            scanf("%d %d %d %d", &u, &v, &l, &a);
            G[u].push_back((edge){v, l, a}), G[v].push_back((edge){u, l, a});
            e[i] = (node){u, v, l, a};
        }
        dijkstra(), sort(e + 1, e + m + 1);
        for (int i = 1; i <= (n << 1); i++) fa[i] = i;
        c = n;
        for (int i = 1; i <= m; i++) {
            int u = find(e[i].u), v = find(e[i].v);
            if (u == v) continue;
            G2[++c].push_back((edge){u, 0, e[i].a});
            G2[u].push_back((edge){c, 0, e[i].a});
            G2[c].push_back((edge){v, 0, e[i].a});
            G2[v].push_back((edge){c, 0, e[i].a});
            fa[u] = fa[v] = c;
        }
        memset(par, 0, sizeof(par));
        dep[c] = 1, dfs(c, 0);
        scanf("%d %d %d", &q, &K, &S);
        lastans = 0;
        for (int i = 1, v, p; i <= q; i++) {
            scanf("%d %d", &v, &p);
            v = (v + K * lastans - 1) % n + 1, p = (p + K * lastans) % (S + 1);
            for (int j = 20; ~j; j--) {
                if (dep[v] - (1 << j) > 0 && mn[v][j] > p) {
                    v = par[v][j];
                }
            }
            printf("%d\n", lastans = dist[v]);
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #112.526 ms77 MB + 888 KBAcceptedScore: 5

Testcase #213.177 ms77 MB + 904 KBAcceptedScore: 5

Testcase #312.756 ms77 MB + 920 KBAcceptedScore: 5

Testcase #413.06 ms77 MB + 940 KBAcceptedScore: 5

Testcase #518.386 ms78 MB + 552 KBAcceptedScore: 5

Testcase #61.264 s156 MB + 964 KBAcceptedScore: 5

Testcase #717.01 ms78 MB + 432 KBAcceptedScore: 5

Testcase #817.126 ms78 MB + 440 KBAcceptedScore: 5

Testcase #917.016 ms78 MB + 436 KBAcceptedScore: 5

Testcase #10987.043 ms145 MB + 284 KBAcceptedScore: 5

Testcase #11988.719 ms145 MB + 296 KBAcceptedScore: 5

Testcase #121.349 s162 MB + 660 KBAcceptedScore: 5

Testcase #131.348 s162 MB + 664 KBAcceptedScore: 5

Testcase #141.349 s162 MB + 676 KBAcceptedScore: 5

Testcase #1518.702 ms78 MB + 584 KBAcceptedScore: 5

Testcase #1618.81 ms78 MB + 588 KBAcceptedScore: 5

Testcase #171.35 s162 MB + 660 KBAcceptedScore: 5

Testcase #181.348 s162 MB + 660 KBAcceptedScore: 5

Testcase #191.934 s166 MB + 120 KBAcceptedScore: 5

Testcase #201.939 s166 MB + 132 KBAcceptedScore: 5


Judge Duck Online | 评测鸭在线
Server Time: 2026-11-23 14:36:04 | Loaded in 1 ms | Server Status
个人娱乐项目,仅供学习交流使用 | 捐赠