Submission #381126

#TimeUsernameProblemLanguageResultExecution timeMemory
381126BlancaHMCarnival (CEOI14_carnival)C++14
20 / 100
130 ms512 KiB
#include <iostream> #include <vector> #include <map> #include <unordered_set> using namespace std; vector<int> par; 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; } 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; 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 (j != root(j)) continue; cout << "2 " << root(i)+1 << " " << root(j)+1 << '\n'; calls++; cin >> ans; if (ans == 1) { merge(root(i), root(j)); break; } } 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...