Submission #381116

#TimeUsernameProblemLanguageResultExecution timeMemory
381116BlancaHMCarnival (CEOI14_carnival)C++14
20 / 100
102 ms1300 KiB
#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) { int root_i = root(i), root_j = root(j); if (root_i == root_j) return; numSets--; par[root_j] = root_i; for (int u: enemies[root_j]) { enemies[root_i].insert(u); enemies[root(u)].insert(root_i); } } void separate(int i, int j) { int root_i = root(i), root_j = root(j); enemies[root_i].insert(root_j); enemies[root_j].insert(root_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; cout << "2 " << (i+1) << " " << j+1 << '\n'; cin >> ans; if (ans == 1) merge(i, j); else separate(i, 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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...