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;
int ufind(int i) {
if (p[i] == i) return i;
return p[i] = ufind(p[i]);
}
void umerge(int a, int b) {
p[a] = b;
}
int min_cardinality(int N) {
p.resize(N);
iota(p.begin(), p.end(), 0);
for (int i = 0; i < N-1; i++) {
move_inside(i);
for (int j = i+1; j < N; j++) {
if (ufind(i) == ufind(j))
continue;
move_inside(j);
int k = press_button();
if (k == 2)
umerge(i, j);
move_outside(j);
}
move_outside(i);
}
map<int,int> m;
for (int i = 0; i < N; i++)
m[ufind(i)]++;
int ans = N;
for (auto it = m.begin(); it != m.end(); it++)
ans = min(ans, it->second);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |