Submission #738965

#TimeUsernameProblemLanguageResultExecution timeMemory
7389651neGame (IOI14_game)C++14
0 / 100
1 ms280 KiB
#include "game.h"
#include <bits/stdc++.h>
using namespace std;
vector<set<int>>pos;
vector<int>with;
void initialize(int n) {
	pos.resize(n);
	with.resize(n,0);
	for (int i = 0;i<n;++i){
		for (int j = 0;j<n;++j){
			if (i != j){
				pos[i].insert(j);
			}
		}
	}	
}
int hasEdge(int u, int v) {
	if (pos[u].find(v)==pos[u].end()){
		return 0;
	}
	 auto join = [&](int a,int b){
	 	vector<int>temp;
	 	for (auto x:pos[a]){
			if (pos[b].find(x) != pos[b].end()){
				temp.push_back(x);
			}
		}
		for (auto x:pos[b]){
			if (pos[a].find(x) != pos[a].end()){
				temp.push_back(x);
			}
		}
		for (auto x:temp){
			if (pos[a].find(x)!=pos[a].end()){
				pos[a].erase(x);
			}
			if (pos[b].find(x)!=pos[b].end()){
				pos[b].erase(x);
			}
		}
	 };
	 auto rem = [&](int a,int b){
	 	if (pos[a].find(b)!=pos[a].end()){
    		pos[a].erase(b);
    	}
    	if (pos[b].find(a)!=pos[b].end()){
    		pos[b].erase(a);
    	}
	 };
	 if (with[u] && with[v]){
	 	rem(u,v);
	 	return 0;
	 }
	 if ((int)pos[u].size() == 1 || (int)pos[v].size() == 1){
	 	join(u,v);
	 	with[u] = 1;
	 	with[v] = 1;
	 	return 1;
	 }
    rem(u,v);
	 return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...