#include <bits/stdc++.h>
using namespace std;
knuth_b gen(rand() % rand() + rand());
typedef pair<int,int> ii;
typedef bitset<161> bt;
const int MAXN = 161;
int pai[MAXN],cor[MAXN],N,C,conjuntos,jafoi;
bt impossivel[MAXN];
int find(int x){
if(x == pai[x]) return x;
return pai[x] = find(pai[x]);
}
void atualiza(int x){
bt novo;
for(int i = 1;i<=N;i++){
if(impossivel[x].test(i)) novo.set(find(i));
}
impossivel[x] = novo;
}
void join(int x,int y){
x = find(x);
y = find(y);
if(x == y) return;
conjuntos--;
if(x > y) swap(x,y);
atualiza(x);
atualiza(y);
pai[y] = x;
impossivel[x] |= impossivel[y];
}
int func(int i){
return gen() % i;
}
int main(){
cin >> N;
conjuntos = N;
cout << N;
for(int i = 1;i<=N;i++){
cout << " ";
cout << i;
pai[i] = i;
}
cout << endl;
cin >> C;
vector<ii> arestas;
for(int i = 1;i<=N;i++){
for(int j = i + 1;j<=N;j++){
arestas.push_back(ii(i,j));
}
}
random_shuffle(arestas.begin(),arestas.end(),func);
while(conjuntos != C && !arestas.empty()){
int u = arestas.back().first;
int v = arestas.back().second;
arestas.pop_back();
u = find(u);
v = find(v);
atualiza(u);
atualiza(v);
if(u == v) continue;
if(impossivel[u].test(v)) continue;
cout << 2 << " " << u << " " << v << endl;
int qtd;
cin >> qtd;
if(qtd == 1){
join(u,v);
}
else{
impossivel[u].set(v);
impossivel[v].set(u);
}
}
cout << 0;
for(int i = 1;i<=N;i++){
cout << " ";
if(cor[find(i)] == 0){
cor[find(i)] = ++jafoi;
}
cout << cor[find(i)];
}
cout << endl;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
420 KB |
Output is correct |
2 |
Correct |
28 ms |
472 KB |
Output is correct |
3 |
Partially correct |
62 ms |
644 KB |
Partially correct |
4 |
Partially correct |
45 ms |
644 KB |
Partially correct |
5 |
Correct |
4 ms |
644 KB |
Output is correct |
6 |
Correct |
3 ms |
644 KB |
Output is correct |
7 |
Correct |
22 ms |
740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
740 KB |
Output is correct |
2 |
Correct |
27 ms |
740 KB |
Output is correct |
3 |
Partially correct |
26 ms |
740 KB |
Partially correct |
4 |
Partially correct |
78 ms |
772 KB |
Partially correct |
5 |
Correct |
4 ms |
772 KB |
Output is correct |
6 |
Correct |
4 ms |
772 KB |
Output is correct |
7 |
Correct |
10 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
772 KB |
Output is correct |
2 |
Correct |
9 ms |
772 KB |
Output is correct |
3 |
Partially correct |
56 ms |
772 KB |
Partially correct |
4 |
Partially correct |
86 ms |
772 KB |
Partially correct |
5 |
Correct |
5 ms |
772 KB |
Output is correct |
6 |
Correct |
4 ms |
772 KB |
Output is correct |
7 |
Correct |
31 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
772 KB |
Output is correct |
2 |
Correct |
10 ms |
772 KB |
Output is correct |
3 |
Partially correct |
68 ms |
772 KB |
Partially correct |
4 |
Partially correct |
44 ms |
772 KB |
Partially correct |
5 |
Correct |
6 ms |
772 KB |
Output is correct |
6 |
Correct |
5 ms |
772 KB |
Output is correct |
7 |
Correct |
25 ms |
772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
772 KB |
Output is correct |
2 |
Correct |
21 ms |
772 KB |
Output is correct |
3 |
Partially correct |
63 ms |
772 KB |
Partially correct |
4 |
Partially correct |
71 ms |
772 KB |
Partially correct |
5 |
Correct |
10 ms |
772 KB |
Output is correct |
6 |
Correct |
4 ms |
772 KB |
Output is correct |
7 |
Partially correct |
92 ms |
772 KB |
Partially correct |