답안 #538699

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
538699 2022-03-17T14:06:29 Z M_W Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
23 ms 360 KB
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
vector<int> adj[513], tmp;
int idx[513], cnt = 0;

void dfs(int a, int p){
	idx[++cnt] = a;
	for(auto x : adj[a]){
		if(x == p) continue;
		dfs(x, a);
	}
	return;
}

int findEgg (int N, vector < pair < int, int > > bridges)
{
	memset(idx, 0, sizeof idx);
	for(int i = 1; i <= N; i++) adj[i].clear();
	cnt = 0;
	
	for(auto x : bridges){
		adj[x.first].push_back(x.second);
		adj[x.second].push_back(x.first);
	}
	dfs(1, 0);

	int l = 1, r = N;
	while(l < r){
		int mid = (l + r) >> 1;
		for(int i = 1; i <= mid; i++) tmp.push_back(idx[i]);
		int q = query(tmp);
		
		if(q) r = mid;
		else l = mid + 1;
		tmp.clear();
	}
	
	return idx[l];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 2 ms 208 KB Number of queries: 4
3 Correct 3 ms 208 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 340 KB Number of queries: 8
2 Correct 13 ms 344 KB Number of queries: 9
3 Correct 17 ms 340 KB Number of queries: 9
4 Correct 17 ms 336 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 360 KB Number of queries: 9
2 Correct 16 ms 352 KB Number of queries: 9
3 Correct 23 ms 344 KB Number of queries: 9
4 Correct 13 ms 360 KB Number of queries: 9