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,ret;
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(dsu[i]!=i) continue; //nije trenutni root
set<int> roots;
for(int j=1;j<=n;j++){
if(root(j)!=i) roots.insert(root(j));
}
cout<<sz(roots)+1<<" "<<i<<" ";
for(auto v:roots){
cout<<v<<" ";
}
cout<<endl;
cin>>ret;
if(ret==sz(roots)+1){
continue;
}
for(auto v:roots){
cout<<2<<" "<<i<<" "<<v<<endl;
cin>>ret;
if(ret==1){
dsu[i]=v;
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.count(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... |