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 <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=155,MAXA=1e6+5,INF=1e9;
const double EPS=1e-9;
#define fi first
#define se second
#define pll pair<ll,ll>
#define pii pair<int,int>
#define mid (l+r)/2
#define sz(a) int((a).size())
#define all(a) a.begin(),a.end()
#define mod 1000000007LL
#define pb push_back
#define PRINT(x) cerr<<#x<<'-'<<x<<endl<<flush;
#define getunique(v) {sort(all(v)); v.erase(unique(all(v)), v.end());}
#define pb push_back
#define pf push_front
#define ppf pop_front
#define ppb pop_back
#define PRINTvec(x) { cerr<<#x<<"-"; for(int i=0;i<sz(x);i++) cerr<<x[i]<<" "; cerr<<endl; }
ll n,m,k,q,x,y,z,input;
string s,t;
ifstream in;
vector<int> dsu;
#ifdef ONLINE_JUDGE
#define in cin
#endif
int root(int x){
while(x!=dsu[x]){
dsu[x]=dsu[dsu[x]];
x=dsu[x];
}
return x;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin>>n;
dsu.resize(n+1);
iota(all(dsu),0);
for(int i=1;i<=n;i++){
if(root(i)!=i) continue; //nije trenutni root
set<int> roots;
for(int j=1;j<=n;j++){
if(root(j)!=i) roots.insert(root(j));
}
int rtsz=sz(roots);
cout<<rtsz+1<<" "<<i<<" ";
for(auto v:roots){
cout<<v<<" ";
}
cout<<endl;
cin>>input;
if(input==rtsz+1){
continue;
}
int numg=sqrt(rtsz)+1;
vector<int> groups[numg];
int tmp=numg,tmpgroup=0;
for(auto v:roots){
groups[tmpgroup].pb(v);
tmp--;
if(tmp==0){
tmp=numg;
tmpgroup++;
}
}
for(int j=0;j<numg;j++){
if(!groups[j].empty()){
cout<<sz(groups[j])+1<<" "<<i<<" ";
for(auto v:groups[j]){
cout<<v<<" ";
}
cout<<endl;
cin>>input;
if(input==sz(groups[j])+1){
continue;
}
else{
for(auto v:groups[j]){
cout<<2<<" "<<i<<" "<<v<<endl;
cin>>input;
if(input==1){
dsu[i]=v;
break;
}
}
break;
}
}
}
}
vector<int> ret;
map<int,int> mp;
int tmp=0;
for(int i=1;i<=n;i++){
ret.pb(root(i));
}
for(int i=0;i<n;i++){
if(!mp[ret[i]]){
mp[ret[i]]=++tmp;
}
}
for(int i=0;i<n;i++){
ret[i]=mp[ret[i]];
}
cout<<0<<" ";
for(auto v:ret){
cout<<v<<" ";
}
return 0;
}
# | 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... |