Submission #269704

# Submission time Handle Problem Language Result Execution time Memory
269704 2020-08-17T08:50:02 Z theStaticMind Easter Eggs (info1cup17_eastereggs) C++14
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#define pb push_back
#define ii pair<int,int>
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define INF 100000000000000000
#define modulo 1000000007
#define mod 998244353
//#define int long long int
using namespace std;

#include "grader.h"

vector<int> adj[1000];
vector<int> sub(1000);
vector<bool> let(1000, false);

void dfs(int x, int pre){
	sub[x] = 1;
	for(auto y : adj[x]){
		if(y == pre || !let[y]) continue;
		dfs(y, x);
		sub[x] += sub[y];
	}
}

void addall(int x, int pre, vector<int>& A){
	A.pb(x);
	for(auto y : adj[x]){
		if(y == pre || !let[y]) continue;
		addall(y, x, A);
	}
}

void split(int x, int pre, int s, vector<int>&L,vector<int>&R){
	L.pb(x);
	R.pb(x);
	s--;
	for(auto y : adj[x]){
		if(y == pre || !let[y]) continue;
		if(s >= sub[y]){
			addall(y, x, left);
			s -= sub[y];
		}
		else {
			addall(y, x, right);
		}
	}
}

int solve(vector<int> comp){
	if(comp.empty()) assert(0);
	int root = comp[0];
	if(sz(comp) == 1) return root;

	vector<int> left, right;

	for(auto x : comp) let[x] = true;
	
	dfs(root, -1);

	split(root, -1, 30, left, right);
	
	for(auto x : comp) let[x] = false;
	
	if(query(left)){
		return solve(left);		
	}
	else {
		return solve(right);		
	}
}

int findEgg (int N, vector < pair < int, int > > bridges)
{	
	for(auto p : bridges){
		adj[p.first].pb(p.second);
		adj[p.second].pb(p.first);
	}
	vector<int> arr;
	for(int i = 1; i <= n; i++) arr.pb(i);
	return solve(arr);
}


Compilation message

eastereggs.cpp: In function 'void split(int, int, int, std::vector<int>&, std::vector<int>&)':
eastereggs.cpp:42:17: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::ios_base&(std::ios_base&)'
   42 |    addall(y, x, left);
      |                 ^~~~
eastereggs.cpp:27:42: note: in passing argument 3 of 'void addall(int, int, std::vector<int>&)'
   27 | void addall(int x, int pre, vector<int>& A){
      |                             ~~~~~~~~~~~~~^
eastereggs.cpp:46:17: error: invalid initialization of reference of type 'std::vector<int>&' from expression of type 'std::ios_base&(std::ios_base&)'
   46 |    addall(y, x, right);
      |                 ^~~~~
eastereggs.cpp:27:42: note: in passing argument 3 of 'void addall(int, int, std::vector<int>&)'
   27 | void addall(int x, int pre, vector<int>& A){
      |                             ~~~~~~~~~~~~~^
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:81:22: error: 'n' was not declared in this scope
   81 |  for(int i = 1; i <= n; i++) arr.pb(i);
      |                      ^