#include "insects.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define sp <<" "<<
#define endl "\n"
int min_cardinality(int N) {
vector<int> sz(N, 1), par(N);
iota(par.begin(), par.end(), 0);
auto find = [&](auto &&find, int u) -> int {
if (u == par[u]) return u;
return par[u] = find(find, par[u]);
};
auto unite = [&](int u, int v) -> void {
u = find(find, u), v = find(find, v);
if (u == v) return;
if (sz[u] < sz[v]) swap(u, v);
par[v] = u;
sz[u] += sz[v];
};
for (int i = 0; i < N; i++) {
move_inside(i);
for (int j = i+1; j < N; j++) {
move_inside(j);
int res = press_button();
if (res == 2) {
unite(i, j);
}
move_outside(j);
}
move_outside(i);
}
int ans = INT_MAX;
for (int i = 0; i < N; i++) {
ans = min(ans, sz[find(find, i)]);
}
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... |