Submission #381123

#TimeUsernameProblemLanguageResultExecution timeMemory
381123BlancaHMCarnival (CEOI14_carnival)C++14
20 / 100
128 ms1424 KiB
#include <iostream> #include <vector> #include <map> #include <unordered_set> using namespace std; vector<int> par; 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; 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 printAll(int N) { for (int i = 0; i < N; i++) { cout << "Person " << i << " root " << root(i) << endl; for (int u: enemies[i]) cout << u << " "; cout << endl; } } 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; enemies.assign(150, unordered_set<int>()); int ans, calls = 1, costumesDiscovered = 0; for (int i = 0; i < N; i++) { if (N - i == C - costumesDiscovered) continue; for (int j = 0; j < i; j++) { if (root(i) == root(j) || enemies[root(i)].find(root(j)) != enemies[i].end()) continue; cout << "2 " << root(i)+1 << " " << root(j)+1 << '\n'; calls++; cin >> ans; if (ans == 1) merge(root(i), root(j)); else separate(root(i), root(j)); } if (par[i] == i) costumesDiscovered++; } } 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...