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 <iostream>
#include <vector>
#include <map>
#include <unordered_set>
#include <set>
using namespace std;
vector<int> par;
set<int> roots;
int root(int a) {
if (a == par[a])
return a;
return par[a] = root(par[a]);
}
void merge(int i, int j) {
if (i == j)
return;
par[j] = i;
roots.erase(j);
}
void solve(int N, int C) {
if (C == 1) {
par.assign(N, 0);
return;
}
par = vector<int>(N);
for (int i = 0; i < N; i++) {
par[i] = i;
//roots.insert(i);
}
int ans, costumesDiscovered = 0;
for (int i = 0; i < N; i++) {
if (N - i == C - costumesDiscovered)
continue;
for (auto it = roots.begin(); it != roots.end(); ) {
int a = *it;
it++;
if (it != roots.end()) {
int b = *it;
it++;
cout << "3 " << a+1 << " " << b+1 << " " << i+1 << '\n';
cin >> ans;
if (ans == 2) {
cout << "2 " << a+1 << " " << i+1 << '\n';
cin >> ans;
if (ans == 1) merge(a, i);
else merge(b, i);
break;
}
} else {
cout << "2 " << a+1 << " " << i+1 << '\n';
cin >> ans;
if (ans == 1) {
merge(a, i);
break;
}
}
}
if (par[i] == i) {
costumesDiscovered++;
roots.insert(i);
}
}
}
int main() {
int N, C;
cin >> N;
cout << N;
for (int i = 1; i <= N; i++)
cout << " " << i;
cout << '\n';
cin >> C;
solve(N, C);
map<int, int> roots;
int c = 1;
for (int i = 0; i < N; i++) {
if (roots.find(root(i)) == roots.end()) {
roots[root(i)] = c++;
}
}
int costumes[N];
for (int i = 0; i < N; i++)
costumes[i] = roots[root(i)];
cout << "0";
for (int i = 0; i < N; i++)
cout << " " << costumes[i];
cout << '\n';
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... |