# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
702493 | math_rabbit_1028 | Game (IOI14_game) | C++14 | 1 ms | 212 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 "game.h"
#include <bits/stdc++.h>
using namespace std;
int root[1515], dep[1515], can[1515], comp, last;
void initialize(int n) {
for (int i = 0; i < n; i++) root[i] = i;
for (int i = 0; i < n; i++) dep[i] = 1;
for (int i = 0; i < n; i++) can[i] = n - 1;
comp = n;
last = n * (n - 1) / 2;
}
int Find(int v) {
if (v == root[v]) return v;
else return root[v] = Find(root[v]);
}
int hasEdge(int u, int v) {
last--;
if (last == 0) return 1;
u = Find(u);
v = Find(v);
//cout << u << " " << v << " " << can[u] << " " << can[v] << "\n";
if (u == v) return 1;
else if (comp <= 2) {
can[u]--;
can[v]--;
return 0;
}
else if (can[u] > 1 && can[v] > 1) {
can[u]--;
can[v]--;
return 0;
}
else {
if (dep[u] > dep[v]) {
root[v] = u;
can[u] = can[u] + can[v] - 2;
}
else if (dep[u] < dep[v]) {
root[u] = v;
can[v] = can[v] + can[u] - 2;
}
else {
root[u] = v;
dep[v] = dep[v]++;
can[v] = can[v] + can[u] - 2;
}
comp--;
return 1;
}
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |