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 "insects.h"
#include <vector>
#include <numeric>
#include <map>
using namespace std;
vector<int> p;
vector<int> sz;
int ufind(int i) {
if (p[i] == i) return i;
return p[i] = ufind(p[i]);
}
int usz(int i) {
return sz[ufind(i)];
}
void umerge(int a, int b) {
if (ufind(a) == ufind(b))
return;
p[a] = b;
sz[b] += sz[a];
}
int min_cardinality(int N) {
p.resize(N);
sz.resize(N);
iota(p.begin(), p.end(), 0);
fill(sz.begin(), sz.end(), 1);
int minsz = N;
for (int i = 0; i < N; i++) {
if (ufind(i) != i)
continue;
move_inside(i);
vector<int> checked;
for (int j = 0; j < N; j++) {
if (ufind(i) == ufind(j))
continue;
if (usz(i) >= minsz)
continue;
for (auto x : checked)
if (ufind(x) == ufind(j))
continue;
move_inside(j);
if (press_button() == 2)
umerge(j, i);
move_outside(j);
checked.push_back(j);
}
move_outside(i);
minsz = min(minsz, usz(i));
}
return minsz;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |