Submission #381118

#TimeUsernameProblemLanguageResultExecution timeMemory
381118BlancaHMCarnival (CEOI14_carnival)C++14
20 / 100
103 ms1260 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) { if (i == j) return; numSets--; par[j] = i; for (int u: enemies[j]) { enemies[i].insert(root(u)); enemies[root(u)].insert(i); } } 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; 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 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...