이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
typedef long long ll;
int n;
vector<int> lnk, sz;
int find(int a) {
if (lnk[a] != a) return lnk[a] = find(lnk[a]);
return lnk[a];
}
void unite(int a, int b) {
a = find(a); b = find(b);
if (a == b) return;
lnk[a] = b;
sz[b] += sz[a];
}
int min_cardinality(int N) {
n = N;
lnk = vector<int>(n);
sz = vector<int>(n, 1);
for (int i = 0; i < n; i++) lnk[i] = i;
for (int i = 0; i < n; i++) {
for (int j = i+1; j < n; j++) {
move_inside(i);
move_inside(j);
if (press_button() > 1) unite(i, j);
move_outside(i);
move_outside(j);
}
}
int mn = n;
for (int i = 0; i < n; i++) {
if (i != lnk[i]) continue;
mn = min(mn, sz[i]);
}
return mn;
}
#ifdef TEST
#include "grader.cpp"
#endif
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |