Submission #476272

# Submission time Handle Problem Language Result Execution time Memory
476272 2021-09-25T19:01:42 Z lovrot Easter Eggs (info1cup17_eastereggs) C++11
Compilation error
0 ms 0 KB
#include <bits/stdc++.h> 
#include "grader.h"

#define X first
#define Y second

using namespace std; 

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

int have;
bool took[1010];

/*
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 ){ 

	for(int i = 0; i < 1010; 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]);

		int 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);
		}
	}

	int ret = 0;

	if(ans.size())
		 ret = ans[0];
	else 
		abort(5);

	memset(took, 0, sizeof(took));
	all.clear(); 
	half.clear();
	help.clear();
	have = 0;

	return ret;
}

/*
int main(){ 
for(int j = 0; j < 3; j++){
	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: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:97:5: error: 'ans' was not declared in this scope; did you mean 'abs'?
   97 |  if(ans.size())
      |     ^~~
      |     abs
eastereggs.cpp:100:10: error: too many arguments to function 'void abort()'
  100 |   abort(5);
      |          ^
In file included from /usr/include/c++/10/bits/std_abs.h:38,
                 from /usr/include/c++/10/cmath:47,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:41,
                 from eastereggs.cpp:1:
/usr/include/stdlib.h:591:13: note: declared here
  591 | extern void abort (void) __THROW __attribute__ ((__noreturn__));
      |             ^~~~~