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 p[1505];
set<int> st[1505];
int find(int x) {
if (p[x] == x) {
return x;
}
p[x] = find(p[x]);
return p[x];
}
void merge(int a, int b) {
a = find(a);
b = find(b);
if (a == b) {
return;
}
p[b] = a;
}
int h = -1, co = 0;
void initialize(int n) {
h = -1;
co = 0;
for (int i = 0; i < n; i++) {
p[i] = i;
}
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
st[i].insert(j);
st[j].insert(i);
}
}
}
int hasEdge(int u, int v) {
if (co == 0) {
h = u;
merge(u, v);
co++;
return 1;
}
if (find(u) == find(v)) {
return 0;
}
if (find(u) == find(h)) {
int co = 0;
for (int x : st[v]) {
if (find(x) == find(h)) {
co++;
}
}
st[v].erase(u);
if (co == 1) {
merge(h, v);
return 1;
} else {
return 0;
}
} else if (find(v) == find(h)) {
int co = 0;
for (int x : st[u]) {
if (find(x) == find(h)) {
co++;
}
}
st[u].erase(v);
if (co == 1) {
merge(h, u);
return 1;
} else {
return 0;
}
} else {
st[v].erase(u);
st[u].erase(v);
return 0;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |