Submission #113985

#TimeUsernameProblemLanguageResultExecution timeMemory
113985E869120Game (IOI14_game)C++14
42 / 100
135 ms132508 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;

class UnionFind {
	public:
	vector<int>par;
	
	void init(int sz) {
		par.resize(sz, -1);
	}
	int root(int pos) {
		if (par[pos] == -1) return pos;
		par[pos] = root(par[pos]);
		return par[pos];
	}
	void unite(int u, int v) {
		u = root(u); v = root(v);
		if (u == v) return;
		par[u] = v;
	}
	bool same(int u, int v) {
		if (root(u) == root(v)) return true;
		return false;
	}
};

int N; bool c[108][108];

void initialize(int n) {
	N = n;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) c[i][j] = true;
	}
}

bool IsConnected() {
	UnionFind UF; UF.init(N); int cnts = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (c[i][j] == true && UF.same(i, j) == false) {
				UF.unite(i, j); cnts++;
			}
		}
	}
	if (cnts == N - 1) return true;
	return false;
}

int hasEdge(int u, int v) {
	if (u > v) swap(u, v);
	c[u][v] = false;
	if (IsConnected() == false) { c[u][v] = true; return 1; }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...