Submission #649385

# Submission time Handle Problem Language Result Execution time Memory
649385 2022-10-10T07:07:49 Z elif Easter Eggs (info1cup17_eastereggs) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

vector<int> adj[520];
vector<int> v;

void dfs(int u, int p){
	v.push_back(u);
	for(auto x : adj[u]){
		if(x != p)
			dfs(x, u);
	}
}
/*
int query(vector < int > islands){
	for(int i=0; i<islands.size(); i++)
		cout << islands[i] << " ";
	int res;
	cin >> res;
	return res;
}
*/
int findEgg(int N, vector<pair<int, int>> bridges){

	for(int i=0; i<N-1; i++){
		int u = bridges[i].first;
		int v = bridges[i].second;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	dfs(1, 0);

	int ans = 0;
	int l = 0, r = v.size() - 1;
	while(l <= r){
		vector<int> islands;
		int mid = (l + r) / 2;
		for(int i=l; i<=mid; i++)
			islands.push_back(v[i]);
		int q = query(islands);
		if(q == 1){
			ans = v[mid];
			r = mid - 1;
		}
		else{
			l = mid + 1;
		}
	}
	return ans;
}

/*
int main(){

	int N;
	cin >> N;
	vector<pair<int, int>> bridges(N);
	for(int i=0; i<N-1; i++){
		cin >> bridges[i].first >> bridges[i].second;
	}
	cout << findEgg(N, bridges) << endl;

	return 0;
}*/

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:41:11: error: 'query' was not declared in this scope
   41 |   int q = query(islands);
      |           ^~~~~