#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;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
4 ms |
344 KB |
Output is correct |
2 |
Correct |
9 ms |
748 KB |
Output is correct |
3 |
Partially correct |
31 ms |
412 KB |
Partially correct |
4 |
Partially correct |
36 ms |
412 KB |
Partially correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
1 ms |
344 KB |
Output is correct |
7 |
Correct |
7 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
8 ms |
344 KB |
Output is correct |
3 |
Partially correct |
19 ms |
408 KB |
Partially correct |
4 |
Partially correct |
38 ms |
412 KB |
Partially correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
6 |
Correct |
2 ms |
344 KB |
Output is correct |
7 |
Correct |
3 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
3 ms |
344 KB |
Output is correct |
3 |
Partially correct |
17 ms |
432 KB |
Partially correct |
4 |
Partially correct |
39 ms |
412 KB |
Partially correct |
5 |
Correct |
3 ms |
344 KB |
Output is correct |
6 |
Correct |
4 ms |
344 KB |
Output is correct |
7 |
Correct |
14 ms |
432 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
344 KB |
Output is correct |
2 |
Correct |
2 ms |
344 KB |
Output is correct |
3 |
Partially correct |
37 ms |
412 KB |
Partially correct |
4 |
Partially correct |
44 ms |
416 KB |
Partially correct |
5 |
Correct |
5 ms |
432 KB |
Output is correct |
6 |
Correct |
11 ms |
440 KB |
Output is correct |
7 |
Correct |
9 ms |
344 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
5 ms |
344 KB |
Output is correct |
3 |
Partially correct |
32 ms |
412 KB |
Partially correct |
4 |
Partially correct |
26 ms |
412 KB |
Partially correct |
5 |
Correct |
14 ms |
428 KB |
Output is correct |
6 |
Partially correct |
38 ms |
416 KB |
Partially correct |
7 |
Partially correct |
39 ms |
424 KB |
Partially correct |