Submission #1350768

#TimeUsernameProblemLanguageResultExecution timeMemory
1350768SulAGame (APIO22_game)C++20
0 / 100
0 ms344 KiB
#include <bits/stdc++.h>
using namespace std;

struct fake_DSU {
    vector<vector<int>> adj, rev;
    vector<bool> to, from;
    int s;
    bool cyclic = false;

    fake_DSU(int n, int s) : adj(n), rev(n), to(n), from(n), s(s) {
        from[s] = to[s] = true;
    }

    void activate(int type, int u) {
        auto &arr = type == 0 ? to : from;
        if (arr[u]) return;
        auto &nxt = type == 0 ? adj[u] : rev[u];
        arr[u] = true;
        for (int v : nxt) {
            if (arr[v]) continue;
            activate(type, v);
        }
    }

    bool add_edge(int u, int v) {
        if (cyclic) return cyclic;
        cyclic |= to[u] && from[v];
        adj[u].push_back(v);
        rev[v].push_back(u);
        if (to[u])
            activate(0, v);
        if (from[v])
            activate(1, u);
        return cyclic;
    }
};

vector<fake_DSU> dsu;

int n;

void init(int _n, int k) {
    n = _n;
    for (int i = 0; i < k; i++)
        dsu.emplace_back(n, i);
    for (int i = 0; i < k-1; i++)
        dsu[i].add_edge(i, i+1);
}

int add_teleporter(int u, int v) {
    cout << "+ " << u << " " << v << endl;
    for (int i = 0; i < dsu.size(); i++) {
        if (dsu[i].add_edge(u, v)) return 1;
//        for (int x = 0; x < n; x++) {
//            if (dsu[i].to[x])
//                cout << "FROM " << i << " TO " << x << "\n";
//            if (dsu[i].from[x])
//                cout << "FROM " << x << " TO " << i << "\n";
//        }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...