이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//Noszály Áron 10o Debreceni Fazekas Mihály Gimnázium
#include "icc.h"
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define FORN(i, n) for(int i=0;i<(n);i++)
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define rep(i, l, r) for ((i) = (l); (i) < (r); (i)++)
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const double PI=acos(-1);
template<typename T> T getint() {
T val=0;
char c;
bool neg=false;
while((c=gc()) && !(c>='0' && c<='9')) {
neg|=c=='-';
}
do {
val=(val*10)+c-'0';
} while((c=gc()) && (c>='0' && c<='9'));
return val*(neg?-1:1);
}
int par[101], sz[101];
void init() {
memset(par, -1, sizeof par);
for(auto&i:sz) i=1;
}
int get(int x) {
if(par[x]==-1) return x;
return par[x]=get(par[x]);
}
void merge(int x, int y) {
int px=get(x), py=get(y);
par[px]=py;
sz[py]+=sz[px];
}
int n_;
vector<int> convert(vector<int> d) {
vector<int> ans;
for(auto i:d) {
for(int j=1;j<=n_;++j) {
if(get(j)==i) ans.pb(j);
}
}
return ans;
}
bool ask(vector<int> a, vector<int> b, bool c=true) {
if(c) {
a=convert(a);
b=convert(b);
}
int A[sz(a)];
int B[sz(b)];
for(int i=0;i<sz(a);++i) A[i]=a[i];
for(int i=0;i<sz(b);++i) B[i]=b[i];
return query(sz(a), sz(b), A, B);
}
pair<int,int> bisect(vector<int> a, vector<int> b) {
if(sz(a)==1 && sz(b)==1) return {a[0], b[0]};
if(sz(a)>sz(b)) swap(a,b);
vector<int> a1,a2;
vector<int> b1,b2;
for(int i=0;i<sz(a)/2;++i) a1.pb(a[i]);
for(int i=sz(a)/2;i<sz(a);++i) a2.pb(a[i]);
for(int i=0;i<sz(b)/2;++i) b1.pb(b[i]);
for(int i=sz(b)/2;i<sz(b);++i) b2.pb(b[i]);
if((rand()&1)==0) {
if(ask(a,b1,false)) return bisect(a, b1);
else return bisect(a, b2);
}else {
if(ask(a,b2,false)) return bisect(a, b2);
else return bisect(a, b1);
}
return {-1,-1};
}
void run(int n) {
init();
n_=n;
int cnt=0;
while(cnt<n-1) {
set<int> groups;
for(int i=1;i<=n;++i) groups.insert(get(i));
vector<int> gs;
for(int i:groups) gs.pb(i);
pair<int,int> el;
vector<int> ord;
for(int i=0;i<log2(sz(gs));++i) {
ord.pb(i);
}
for(auto i:ord) {
vector<int> ga,gb;
for(int j=0;j<sz(gs);++j) {
if(j&(1<<i)) ga.pb(gs[j]);
else gb.pb(gs[j]);
}
if(ask(ga, gb)) {
// cerr<<"ok\n";
el=bisect(convert(ga), convert(gb));
break ;
}
}
// cerr<<el.xx<<" "<<el.yy<<"\n";
setRoad(el.xx, el.yy);
merge(el.xx, el.yy);
cnt++;
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |