Submission #674101

# Submission time Handle Problem Language Result Execution time Memory
674101 2022-12-23T05:28:40 Z QwertyPi Easter Eggs (info1cup17_eastereggs) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#define TEST
using namespace std;

bool in[513] = {0, 0, 0, 0, 0, 1};

#ifdef TEST
int query(vector<int> islands){
	cout << "Query: ";
	for(auto i : islands){
		cout << i << ' ';
	}
	bool y = false;
	for(auto i : islands){
		y |= in[i];
	}
	cout << (y ? "YES" : "NO") << endl;
	return y;
}
#else
int query(vector<int> islands);
#endif

vector<int> G[513];

int c = 0, tot = 512;
int u[513], elim[513];
void dfs(int t, int v, int par = -1){
	if(c == tot) return;
	if(u[v] == 0) c++, u[v] = t;
	for(auto i : G[v]){
		if(i == par || elim[i])
			continue;
		dfs(t, i, v);
	}
}

int findEgg(int N, vector<pair<int, int>> bridges){
	for(int i = 1; i <= N; i++){
		G[i].clear();
	}
	for(int i = 0; i < N - 1; i++){
		G[bridges[i].first].push_back(bridges[i].second);
		G[bridges[i].second].push_back(bridges[i].first);
	}
	for(int i = (N + 1) / 2, t = 1; i != 1; t++){
		cout << i << ' ' << t << endl;
		c = 0; tot = i; dfs(t, 1);
		vector<int> islands;
		for(int j = 1; j <= N; j++){
			if(u[j]) islands.push_back(j);
		}
		int r = query(islands);
		if(i <= 1){
			if(!r){
				for(int j = 1; j <= N; j++){
					if(u[j] == 0) return j;
				} 
			}else{
				for(int j = 1; j <= N; j++){
					if(u[j] == t) return j;
				} 
			}
		}
		if(!r){
			i = i - (i + 1) / 2;
			continue;
		}else{
			i = (i + 1) / 2;
			for(int j = 1; j <= N; j++){
				if(u[j] == 0) elim[j] = true;
				if(u[j] == t) u[j] = 0;
			}
		}
	}
}

#ifdef TEST
int main(){
	cout << findEgg(5, {{1, 2}, {1, 3}, {2, 4}, {2, 5}}) << endl;
}
#endif

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:76:1: warning: control reaches end of non-void function [-Wreturn-type]
   76 | }
      | ^
/usr/bin/ld: /tmp/ccAhVk1I.o: in function `query(std::vector<int, std::allocator<int> >)':
grader.cpp:(.text+0x0): multiple definition of `query(std::vector<int, std::allocator<int> >)'; /tmp/ccCw4UvH.o:eastereggs.cpp:(.text+0x50): first defined here
/usr/bin/ld: /tmp/ccAhVk1I.o: in function `main':
grader.cpp:(.text.startup+0x0): multiple definition of `main'; /tmp/ccCw4UvH.o:eastereggs.cpp:(.text.startup+0x0): first defined here
collect2: error: ld returned 1 exit status