# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|
366793 | | KoD | Game (IOI14_game) | C++17 | | 507 ms | 28368 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
struct DSU {
std::vector<int> par;
DSU() { }
DSU(const int n): par(n, -1) { }
int find(const int u) {
return par[u] < 0 ? u : par[u] = find(par[u]);
}
void absorb(int u, int v) {
u = find(u);
v = find(v);
if (u == v) {
return;
}
par[v] = u;
}
};
DSU dsu;
int N;
int count[2000][2000];
void initialize(int n) {
N = n;
dsu = DSU(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < n; ++j) {
if (i != j) {
count[i][j] = 1;
}
}
}
}
int hasEdge(int u, int v) {
u = dsu.find(u);
v = dsu.find(v);
if (count[u][v] == 1) {
for (int i = 0; i < N; ++i) {
count[u][i] += count[v][i];
count[i][u] += count[v][i];
}
dsu.absorb(u, v);
return 1;
}
else {
count[u][v] -= 1;
count[v][u] -= 1;
return 0;
}
}
#ifdef __APPLE__
int main() {
int n;
std::cin >> n;
initialize(n);
for (int i = 0; i < n; ++i) {
for (int j = 0; j < i; ++j) {
int u, v;
std::cin >> u >> v;
std::cout << hasEdge(u, v) << '\n';
}
}
}
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |