Submission #475725

# Submission time Handle Problem Language Result Execution time Memory
475725 2021-09-23T21:14:31 Z lovrot Easter Eggs (info1cup17_eastereggs) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h> 
#include <unordered_set>
#include "grader.h"

#define X first
#define Y second

using namespace std; 

vector<int> g[530];
vector<int> half;
vector<int> all; 
vector<int> help;

int have;
bool took[530];

//int egg;

bool query(vector< int > v): /*{ 
	for(int x : v)
		if(x == egg)
			return true;
	return false;
} */

void findHalf(int x){ 
	if(have == 0)
		return;

	took[x] = true;
	half.push_back(x);

	have--;
	for(int y : g[x]){ 
		if(took[y] == true) 
			continue;

		findHalf(y);
	}
} 

int findEgg (int n, vector< pair< int, int > > graf ){ 
	memset(took, 0, sizeof(took));

	for(int i = 0; i <= n; i++)
		g[i].clear();

	for(int i = 0; i < n - 1; i++){ 
		int x = graf[i].X;
		int y = graf[i].Y;

		g[x].push_back(y);
		g[y].push_back(x);
	
		if(!took[x]){ 
			all.push_back(x);
			took[x] = true; 
		}
		if(!took[y]){ 
		 	all.push_back(y);
		 	took[y] = true;
		}
	}
	
	memset(took, false, sizeof(took));

	while(all.size() > 1){ 
		have = n / 2;
		half.clear();

		findHalf(all[0]);

		bool ans = query(half);

		if(ans){ 
			n /= 2;
		}
		else{ 
			n = n - n / 2;
		}

		help.clear();
		for(int x : all){ 
			if(took[x] == ans)
				help.push_back(x);
		}

		all.clear();
		for(int x : help){
			took[x] = false;
			all.push_back(x);
		}
	}

	return all[0];
}
/*
int main(){ 
	int m;
	cout << "num. of nodes\n";

	cin >> m;

	cout << "easter egg\n";
	cin >> egg;

	vector< pair<int, int> > inp;

	for(int i = 0; i < m - 1; i++){ 
		int a, b;
		cin >> a >> b;

		inp.push_back({a, b});
	}
	
	cout << findEgg(m, inp);
	return 0;	
} */

Compilation message

eastereggs.cpp:20:6: error: ambiguating new declaration of 'bool query(std::vector<int>)'
   20 | bool query(vector< int > v): /*{
      |      ^~~~~
In file included from eastereggs.cpp:3:
grader.h:6:5: note: old declaration 'int query(std::vector<int>)'
    6 | int query(vector < int > islands);
      |     ^~~~~
eastereggs.cpp: In function 'bool query(std::vector<int>)':
eastereggs.cpp:27:1: error: only constructors take member initializers
   27 | void findHalf(int x){
      | ^~~~
eastereggs.cpp:27:1: error: expected identifier before 'void'
eastereggs.cpp:27:1: error: expected '{' before 'void'
eastereggs.cpp:27:1: warning: no return statement in function returning non-void [-Wreturn-type]