Submission #349054

#TimeUsernameProblemLanguageResultExecution timeMemory
349054NachoLibreGame (IOI14_game)C++14
100 / 100
519 ms25400 KiB
#include <bits/stdc++.h>
using namespace std;
#ifndef wambule
#include "game.h"
#endif

const int N = 1503;
int opw[N], r[N][N], globn;
int P(int x) {
	return (opw[x] ^ -1 ? opw[x] = P(opw[x]) : x);
}

void initialize(int n) {
	// hello wambule
	globn = n;
	for(int i = 0; i < n; ++i) {
		opw[i] = -1;
		for(int j = 0; j < n; ++j)
			r[i][j] = (i != j);
	}
}

int hasEdge(int x, int y) {
	int n = globn;
	x = P(x);
	y = P(y);
	assert(x ^ y);
	--r[x][y];
	--r[y][x];
	if(r[x][y])
		return 0;
	for(int i = 0; i < n; ++i) {
		r[x][i] += r[y][i];
		r[i][x] += r[i][y];
		r[i][y] = r[y][i] = 0;
	}
	opw[y] = x;
	return 1;
}

#ifdef wambule
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	initialize(n);
	for(int i = 0; i < n * (n - 1) / 2; ++i) {
		int x, y;
		cin >> x >> y;
		cout << hasEdge(x, y) << "\n";
	}
	return 0;
}
#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...