QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#676956#4251. Gamemakrav0 1ms3852kbC++203.8kb2024-10-26 05:37:332024-10-26 05:37:34

Judging History

你现在查看的是最新测评结果

  • [2024-10-26 05:37:34]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:3852kb
  • [2024-10-26 05:37:33]
  • 提交

answer

#include "game.h"
#include <bits/stdc++.h>

using namespace std;

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define pb push_back

struct dsu {
    int n, k;
    vector<int> par, siz, sum;
    dsu() = default;
    dsu(int n_, int k_) {
        n = n_;
        k = k_;
        sum.assign(n, 0);
        for (int i = 0; i < k; i++) sum[i] = 1;
        par.assign(n, 0);
        siz.assign(n, 1);
        iota(all(par), 0);
    }
    int get(int v) {return (par[v] == v ? v : par[v] = get(par[v]));}
    bool merge(int u, int v) {
        u = get(u); v = get(v);
        if (u == v) return false;
        if (siz[u] < siz[v]) swap(u, v);
        par[v] = u;
        sum[u] += sum[v];
        siz[u] += siz[v];
        return (sum[u] >= 2);
    }
};

struct dynamic_scc {
    const int MAXLVL = 19;
    int n, k, step;
    vector<vector<pair<int, int>>> edg_arrs;
    vector<vector<int>> g, grev;
    vector<int> used_dfs, used;
    vector<dsu> dp_dsu;

    dynamic_scc() = default;
    void init(int n_, int k_) {
        step = 0;
        n = n_;
        k = k_;
        used_dfs.assign(n, 0); used.assign(n, 0);
        g.resize(n); grev.resize(n);
        edg_arrs.resize(MAXLVL);
        dp_dsu.resize(MAXLVL, dsu(n, k));
    }

    bool add_edge(pair<int, int> new_edge) {
        if (new_edge.first == new_edge.second) return new_edge.first < k;
        step++;
        int fb = 0;
        while (!edg_arrs[fb].empty()) fb++;
        for (int j = 0; j < fb; j++) {
            for (auto edg : edg_arrs[j]) {
                edg_arrs[fb].push_back(edg);
            }
            edg_arrs[j].clear();
        }
        edg_arrs[fb].pb(new_edge);

        vector<int> iverts(2 * sz(edg_arrs[fb]));
        for (int i = 0; i < sz(edg_arrs[fb]); i++) {
            int u = edg_arrs[fb][i].first, v = edg_arrs[fb][i].second;
            int cu = dp_dsu[fb].get(u), cv = dp_dsu[fb].get(v);
            if (cu == cv) continue;
            if (used[cu] != step) {
                g[cu].clear(); grev[cu].clear();
                used[cu] = step;
            }
            if (used[cv] != step) {
                g[cv].clear(); grev[cv].clear();
                used[cv] = step;
            }
            g[cu].push_back(cv);
            grev[cv].push_back(cu);
            iverts[2 * i] = cu; iverts[2 * i + 1] = cv;
        }

        vector<int> order;
        auto dfs = [&](int v, auto&&self) -> void {
            used_dfs[v] = step;
            for (int u : g[v]) {
                if (used_dfs[u] != step) {
                    self(u, self);
                }
            }
            order.push_back(v);
        };
        for (int vt : iverts) {
            if (used_dfs[vt] != step) {
                dfs(vt, dfs);
            }
        }

        step++;
        vector<pair<int, int>> dsu_adds;
        auto dfs2 = [&](int v, auto&&self) -> void {
            used_dfs[v] = step;
            for (int u : grev[v]) {
                if (used_dfs[u] != step) {
                    dsu_adds.emplace_back(v, u);
                    self(u, self);
                }
            }
        };
        for (int ind = sz(order) - 1; ind >= 0; ind--) {
            if (used_dfs[order[ind]] != step) {
                dfs2(order[ind], dfs2);
            }
        }
        bool nice = false;
        for (int j = 0; j <= fb; j++) {
            for (auto edg : dsu_adds) {
                nice |= dp_dsu[j].merge(edg.first, edg.second);
            }
        }
        return nice;
    }
};

dynamic_scc dscc;

void init(int n, int k) {
    dscc.init(n, k);
    for (int i = 0; i < k - 1; i++) dscc.add_edge({i, i + 1});
}

int add_teleporter(int u, int v) {
    return dscc.add_edge({u, v});
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 2
Accepted
time: 1ms
memory: 3852kb

input:

1 1
1
893123 893123
-1

output:

0

result:

ok interaction finished.

Test #2:

score: 2
Accepted
time: 0ms
memory: 3796kb

input:

9 9
29
893122 893124
893121 893127
893120 893124
893123 893121
893122 893131
893125 893131
893121 893126
893123 893126
893126 893131
893123 893131
893123 893125
893123 893124
893127 893125
893120 893126
893123 893120
893121 893131
893123 893127
893122 893126
893122 893127
893127 893131
893122 893125...

output:

28

result:

ok interaction finished.

Test #3:

score: 2
Accepted
time: 0ms
memory: 3836kb

input:

100 100
80
893180 893071
893134 893063
893150 893091
893127 893178
893142 893177
893153 893156
893127 893137
893174 893065
893127 893070
893126 893061
893171 893089
893173 893072
893153 893058
893156 893074
893151 893068
893136 893060
893120 893083
893073 893091
893148 893163
893073 893088
893156 89...

output:

80
80
80
59

result:

ok interaction finished.

Test #4:

score: 0
Wrong Answer
time: 1ms
memory: 3796kb

input:

45 45
80
893143 893167
893122 893132
893123 893140
893120 893139
893158 893167
893154 893163
893133 893137
893133 893142
893135 893137
893121 893135
893137 893149
893141 893152
893122 893167
893128 893145
893140 893167
893122 893127
893134 893142
893122 893129
893141 893156
893146 893149
893123 8931...

output:

80
50

result:

wrong answer Wrong Answer [1]

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Skipped

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #1:

0%