提交记录 3736


用户 题目 状态 得分 用时 内存 语言 代码长度
pinkrabbit noi18a. 【NOI2018】归程 Accepted 100 1.543 s 254124 KB C++ 2.89 KB
提交时间 评测时间
2018-07-18 16:03:33 2020-07-31 21:25:57
#include<queue>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;

const int maxn = 6e5 + 10;

struct E {
    int u, v, l, a;
    bool operator < (const E& A) const { return a > A.a; }
} e[maxn];

struct Edge {
    Edge* next;
    int to, w;
    Edge(Edge* next = 0, int to = 0, int w = 0): next(next), to(to), w(w) {}
} *first[maxn], *f2[maxn];

int n, m, f[maxn], d[maxn], vis[maxn], de[maxn], c, q, k, s, vi[maxn][20], pi[maxn][20];

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

struct Node {
    int u, w;
    Node(int u = 0, int w = 0): u(u), w(w) {}
    bool operator < (const Node& A) const { return w > A.w; }
};

void Dijkstra() {
    priority_queue<Node> Q; Q.push(Node(1, 0));
    memset(d, 0x3f, sizeof d), d[1] = 0;
    memset(vis, 0, sizeof vis);
    while (!Q.empty()) {
        Node x = Q.top(); Q.pop();
        if (vis[x.u]) continue;
        vis[x.u] = 1;
        for (Edge* now = first[x.u]; now; now = now->next) {
            if (d[now->to] > d[x.u] + now->w) {
                d[now->to] = d[x.u] + now->w;
                Q.push(Node(now->to, d[now->to]));
            }
        }
    }
}

void Add(int u, int v, int w) {
    f2[u] = new Edge(f2[u], v, w);
    f2[v] = new Edge(f2[v], u, w);
}

void Dfs(int u, int pa) {
    for (int i = 1; (1 << i) <= c; i++) pi[u][i] = pi[pi[u][i - 1]][i - 1];
    for (int i = 1; (1 << i) <= c; i++) vi[u][i] = min(vi[u][i - 1], vi[pi[u][i - 1]][i - 1]);
    for (Edge* now = f2[u]; now; now = now->next) {
        if (now->to == pa) continue;
        pi[now->to][0] = u, vi[now->to][0] = now->w;
        de[now->to] = de[u] + 1, Dfs(now->to, u);
        d[u] = min(d[u], d[now->to]);
    }
}

int main() {
    int T; scanf("%d", &T);
    while (T--) {
        memset(first, 0, sizeof first);
        memset(f2, 0, sizeof f2);
        scanf("%d%d", &n, &m);
        for (int i = 1; i <= m; i++) {
            scanf("%d%d%d%d", &e[i].u, &e[i].v, &e[i].l, &e[i].a);
            first[e[i].u] = new Edge(first[e[i].u], e[i].v, e[i].l);
            first[e[i].v] = new Edge(first[e[i].v], e[i].u, e[i].l);
        }
        Dijkstra();
        sort(e + 1, e + 1 + m);
        for (int i = 1; i <= n << 1; i++) f[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;
            Add(++c, u, e[i].a), Add(c, v, e[i].a);
            f[u] = f[v] = c;
        }
        memset(pi, 0, sizeof pi);
        de[c] = 1, Dfs(c, 0);
        int ans = 0;
        scanf("%d%d%d", &q, &k, &s);
        while (q--) {
            int v, p; scanf("%d%d", &v, &p);
            v = (v + k * ans - 1) % n + 1;
            p = (p + k * ans) % (s + 1);
            for (int i = 19; ~i; i--) {
                if (de[v] - (1 << i) > 0 && vi[v][i] > p) {
                    v = pi[v][i];
                }
            }
            printf("%d\n", ans = d[v]);
        }
    }
    return 0;
}

CompilationN/AN/ACompile OKScore: N/A

Testcase #19.223 ms59 MB + 556 KBAcceptedScore: 5

Testcase #29.245 ms59 MB + 568 KBAcceptedScore: 5

Testcase #39.409 ms59 MB + 612 KBAcceptedScore: 5

Testcase #49.598 ms59 MB + 660 KBAcceptedScore: 5

Testcase #514.11 ms61 MB + 36 KBAcceptedScore: 5

Testcase #6858.077 ms240 MB + 224 KBAcceptedScore: 5

Testcase #713.072 ms60 MB + 728 KBAcceptedScore: 5

Testcase #813.061 ms60 MB + 736 KBAcceptedScore: 5

Testcase #913.065 ms60 MB + 732 KBAcceptedScore: 5

Testcase #10730.958 ms210 MB + 412 KBAcceptedScore: 5

Testcase #11733.137 ms210 MB + 420 KBAcceptedScore: 5

Testcase #12959.696 ms244 MB + 704 KBAcceptedScore: 5

Testcase #13959.079 ms244 MB + 708 KBAcceptedScore: 5

Testcase #14959.022 ms244 MB + 728 KBAcceptedScore: 5

Testcase #1514.568 ms61 MB + 60 KBAcceptedScore: 5

Testcase #1614.561 ms61 MB + 64 KBAcceptedScore: 5

Testcase #17959.438 ms244 MB + 708 KBAcceptedScore: 5

Testcase #18958.623 ms244 MB + 704 KBAcceptedScore: 5

Testcase #191.537 s248 MB + 152 KBAcceptedScore: 5

Testcase #201.543 s248 MB + 172 KBAcceptedScore: 5


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