Submission #334565

# Submission time Handle Problem Language Result Execution time Memory
334565 2020-12-09T12:21:26 Z nandonathaniel Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
21 ms 492 KB
#include <bits/stdc++.h>
#include "grader.h"

using namespace std;

const int MAXN=515;

vector<int> adj[MAXN];
int preorder[MAXN],nomor[MAXN],idx;

void dfs(int now,int par){
	idx++;
	preorder[idx]=now;
	for(auto nxt : adj[now]){
		if(nxt==par)continue;
		dfs(nxt,now);
	}
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
	idx=0;
	for(int i=1;i<=N;i++)adj[i].clear();
    for(int i=0;i<N-1;i++){
    	adj[bridges[i].first].push_back(bridges[i].second);
    	adj[bridges[i].second].push_back(bridges[i].first);
	}
	dfs(1,-1);
	int ki=1,ka=N;
	while(ki<ka){
//		cout << ki << " " << ka << endl;
		int mid=(ki+ka)/2;
		vector<int> v;
		for(int i=1;i<=mid;i++)v.push_back(preorder[i]);
		if(query(v)){
			ka=mid;
		}
		else ki=mid+1;
	}
    return preorder[ki];
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Number of queries: 4
2 Correct 1 ms 364 KB Number of queries: 4
3 Correct 1 ms 384 KB Number of queries: 4
4 Correct 1 ms 384 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 7 ms 364 KB Number of queries: 8
2 Correct 15 ms 492 KB Number of queries: 9
3 Correct 21 ms 364 KB Number of queries: 9
4 Correct 18 ms 364 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 20 ms 364 KB Number of queries: 9
2 Correct 17 ms 384 KB Number of queries: 9
3 Correct 18 ms 364 KB Number of queries: 9
4 Correct 18 ms 364 KB Number of queries: 9