Submission #119323

#TimeUsernameProblemLanguageResultExecution timeMemory
119323Mamnoon_SiamGame (IOI14_game)C++17
42 / 100
1075 ms3652 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;

const int maxn = 1.5e3 + 5;

int N;
int g[maxn][maxn];
int vis[maxn];

void delete_edge(int u, int v) {
	g[u][v] = g[v][u] = 0;
}
void add_edge(int u, int v) {
	g[u][v] = g[v][u] = 1;
}
void dfs(int u, int &cnt) {
	vis[u] = 1;
	cnt++;
	for(int i = 0; i < N; i++) {
		if(g[u][i] and !vis[i]) {
			dfs(i, cnt);
		}
	}
}
bool connected() {
	for(int i = 0; i < N; i++) {
		vis[i] = 0;
	}
	int cnt = 0;
	dfs(0, cnt);
	return cnt != N ? 0 : 1;
}

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

int hasEdge(int u, int v) {
	delete_edge(u, v);
	if(connected()) {
		return 0;
	} else {
		add_edge(u, v);
		return 1;
	}
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...