Submission #47614

# Submission time Handle Problem Language Result Execution time Memory
47614 2018-05-05T19:22:20 Z IvanC Carnival (CEOI14_carnival) C++17
20 / 100
110 ms 752 KB
#include <bits/stdc++.h>
using namespace std;

knuth_b gen(1337);

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 424 KB Output is correct
2 Correct 31 ms 568 KB Output is correct
3 Partially correct 68 ms 628 KB Partially correct
4 Partially correct 76 ms 700 KB Partially correct
5 Correct 5 ms 700 KB Output is correct
6 Correct 3 ms 752 KB Output is correct
7 Correct 24 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 752 KB Output is correct
2 Correct 29 ms 752 KB Output is correct
3 Partially correct 24 ms 752 KB Partially correct
4 Partially correct 84 ms 752 KB Partially correct
5 Correct 4 ms 752 KB Output is correct
6 Correct 3 ms 752 KB Output is correct
7 Correct 11 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 752 KB Output is correct
2 Correct 10 ms 752 KB Output is correct
3 Partially correct 40 ms 752 KB Partially correct
4 Partially correct 108 ms 752 KB Partially correct
5 Correct 5 ms 752 KB Output is correct
6 Correct 4 ms 752 KB Output is correct
7 Correct 22 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 752 KB Output is correct
2 Correct 9 ms 752 KB Output is correct
3 Partially correct 74 ms 752 KB Partially correct
4 Partially correct 47 ms 752 KB Partially correct
5 Correct 6 ms 752 KB Output is correct
6 Correct 4 ms 752 KB Output is correct
7 Correct 34 ms 752 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 752 KB Output is correct
2 Correct 19 ms 752 KB Output is correct
3 Partially correct 65 ms 752 KB Partially correct
4 Partially correct 78 ms 752 KB Partially correct
5 Correct 9 ms 752 KB Output is correct
6 Correct 7 ms 752 KB Output is correct
7 Partially correct 110 ms 752 KB Partially correct