Submission #908848

#TimeUsernameProblemLanguageResultExecution timeMemory
908848vjudge1Carnival (CEOI14_carnival)C++17
20 / 100
44 ms748 KiB
#include <bits/stdc++.h> #define TAM 152 using namespace std; int n; int padreAbs[TAM]; int actualF = 1; map <int, int> costumes; bool marked[TAM]; int encontrar(int obj){ if(padreAbs[obj] == obj) return obj; return padreAbs[obj] = encontrar(padreAbs[obj]); } void unir(int a, int b){ int padreA = encontrar(a); int padreB = encontrar(b); if(padreA == padreB || marked[padreA] || marked[padreB]) return; int answer; cout << "2 " << padreA << " " << padreB << endl; cout.flush(); cin >> answer; if(answer == 1) padreAbs[padreB] = padreA; } int main(){ cin >> n; for(int i = 1; i <= n; i++) padreAbs[i] = i; for(int i = 1; i < n; i++){ for(int j = i + 1; j <= n; j++){ unir(i, j); } marked[i] = 1; } for(int i = 1; i <= n; i++){ int padreI = encontrar(i); if(costumes.find(padreI) == costumes.end()){ costumes.insert({padreI, actualF}); actualF++; } } cout << "0 "; for(int i = 1; i <= n; i++){ int padreI = encontrar(i); cout << costumes[padreI] << " "; } 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...