이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "insects.h"
using namespace std;
#define pb push_back
#define ll long long
#define fi first
#define se second
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int nax=5005;
int parent[nax];
int sz[nax];
int find(int x){
if(parent[x]==x) return x;
return parent[x]=find(parent[x]);
}
bool sameset(int x,int y){
return find(x)==find(y);
}
void joinset(int x,int y){
x=find(x);
y=find(y);
parent[x]=y;
sz[y]+=sz[x];
return;
}
int min_cardinality(int N) {
vector<pair<int,int>> tab;
for (int i = 0; i < N; ++i)
{
parent[i]=i;
sz[i]=1;
}
for (int i = 0; i < N; ++i)
{
for (int j = i+1; j < N; ++j)
{
tab.pb({i,j});
}
}
int cnt=0;
shuffle(tab.begin(),tab.end(),rng);
for (int i = 0; i < min(N*(N-1)/2,20000); ++i)
{
if(sameset(tab[i].fi,tab[i].se)) continue;
cnt++;
move_inside(tab[i].fi);
move_inside(tab[i].se);
int a=press_button();
move_outside(tab[i].fi);
move_outside(tab[i].se);
if(a==2) joinset(tab[i].fi,tab[i].se);
}
int mn=1e9;
for (int i = 0; i < N; ++i)
{
mn=min(mn,sz[find(i)]);
}
return mn;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |