답안 #410451

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
410451 2021-05-22T17:15:56 Z nichke Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
25 ms 472 KB
#include <bits/stdc++.h>
using namespace std;

vector< int > vi;
vector< int > euler;
vector< int > adj[513];

int query(vector <int> );

void dfs(int v, int p = -1) {
	euler.push_back(v);
	for (int u : adj[v]) {
		if (u == p) continue;
		dfs(u, v);
	}
}

int check_query(int x) {
	vi.clear();
	for (int i = 0; i <= x; i++) {
		vi.push_back(euler[i]);
	}
	return query(vi);   
}

int findEgg(int N, vector< pair <int, int> > bridges) {
	euler.clear();
	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);
	int res = -1;
	int l = 0, r = euler.size() - 2;
	while (l <= r) {
		int m = (l + r) / 2;
		if (check_query(m)) {
			r = m - 1;
			res = m;
		} else {
			l = m + 1;
		}
	}
	if (res == -1) {
		return euler.back();
	}
	return euler[res];
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 200 KB Number of queries: 4
2 Correct 1 ms 200 KB Number of queries: 4
3 Correct 1 ms 200 KB Number of queries: 4
4 Correct 2 ms 200 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 472 KB Number of queries: 8
2 Correct 13 ms 448 KB Number of queries: 9
3 Correct 20 ms 332 KB Number of queries: 9
4 Correct 17 ms 348 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 356 KB Number of queries: 9
2 Correct 16 ms 348 KB Number of queries: 9
3 Correct 17 ms 340 KB Number of queries: 9
4 Correct 17 ms 328 KB Number of queries: 9