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>
using namespace std;
vector<int> par;
int numSets;
vector<unordered_set<int>> enemies;
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;
numSets--;
par[j] = i;
for (int u: enemies[j]) {
enemies[i].insert(root(u));
enemies[root(u)].insert(i);
enemies[root(u)].erase(j);
}
}
void separate(int i, int j) {
enemies[i].insert(j);
enemies[j].insert(i);
}
void solve(int N, int C) {
numSets = N;
if (C == 1) {
par.assign(N, 0);
return;
}
par = vector<int>(N);
for (int i = 0; i < N; i++)
par[i] = i;
enemies.assign(150, unordered_set<int>());
int ans;
for (int i = 0; i < N; i++) {
if (numSets == C)
break;
for (int j = i+1; j < N; j++) {
if (numSets == C)
break;
if (root(i) == root(j) || enemies[root(i)].find(root(j)) != enemies[i].end())
continue;
if (enemies[root(i)].size() == enemies[root(j)].size() && (int) enemies[root(i)].size() == C-1) {
merge(root(i), root(j));
continue;
}
cout << "2 " << root(i)+1 << " " << root(j)+1 << '\n';
cin >> ans;
if (ans == 1)
merge(root(i), root(j));
else
separate(root(i), root(j));
}
}
}
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... |