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<pair<int, 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;
}
void initialize(int n) {
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({i, j});
st[j].insert({i, j});
}
}
}
int hasEdge(int u, int v) {
int a = u, b = v;
u = min(a, b);
v = max(a, b);
set<pair<int, int>> todel;
for (auto [p, q] : st[u]) {
if (find(p) == find(q)) {
todel.insert({p, q});
}
}
for (auto p : todel) {
st[u].erase(p);
}
todel.clear();
for (auto [p, q] : st[v]) {
if (find(p) == find(q)) {
todel.insert({p, q});
}
}
for (auto p : todel) {
st[v].erase(p);
}
if (st[u].empty() || st[v].empty()) {
return 0;
}
if (st[u].size() < 2 || st[v].size() < 2) {
st[u].erase({u, v});
st[v].erase({u, v});
merge(u, v);
return 1;
}
st[u].erase({u, v});
st[v].erase({u, 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... |