Submission #243011

# Submission time Handle Problem Language Result Execution time Memory
243011 2020-06-30T07:27:13 Z Exile_2k4 Easter Eggs (info1cup17_eastereggs) C++17
0 / 100
400 ms 384 KB
#include <bits/stdc++.h>
#include "grader.h"
 
using namespace std;
 
const int sz = 600;
 
#define pii pair<int,int>
 
vector<int> g[sz], call;
 
bool exist[sz], nxt[sz];
 
void dfs(int p,int u, int need){
	if(exist[u] && call.size()<need) call.push_back(u);
	for(auto v:g[u]) if(v!=p && exist[v]) dfs(u,v,need);
}

//int query(vector<int> e){
//	for(auto v:e) cout << v << " ";
//	cout << endl;
//	int verd;
//	cin >> verd;
//	return verd;
//}
 
int findEgg(int N, vector<pii> bridges){
	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);
	}
	memset(exist,1,sizeof(exist));
	
	int cnt = N;
	while(cnt!=1){
		int mid = (cnt+1)/2;
		call.clear();
		for(int i=1;i<=N;++i) if(exist[i]){
			dfs(i,i,mid);
			break;
		}
      	memset(nxt,0,sizeof(nxt));
		if(query(call)){
			for(auto v:call) nxt[v] = 1;
            for(int i=1;i<=N;++i) exist[i] = nxt[i];
			cnt = call.size();
		}else{
			for(auto v:call) exist[v] = 0;
			cnt -= call.size();
		}
	}
	for(int i=1;i<=N;++i) if(exist[i]) return i;
}

//signed main(){
//	int n;
//	cin >> n;
//	vector<pii> e(n-1);
//	for(int i=0;i<n-1;++i) cin >> e[i].first >> e[i].second;
//	cout << findEgg(n,e);
//}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int, int)':
eastereggs.cpp:15:28: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if(exist[u] && call.size()<need) call.push_back(u);
                 ~~~~~~~~~~~^~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:53:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# Verdict Execution time Memory Grader output
1 Execution timed out 3087 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3079 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 3074 ms 384 KB Time limit exceeded
2 Halted 0 ms 0 KB -