답안 #357675

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
357675 2021-01-24T12:00:54 Z Mlxa Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
22 ms 492 KB
#ifdef LC
#include "pch.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;
#define all(x) x.begin(), x.end()
#define x first
#define y second
#define mp make_pair
#define mt make_tuple

int query(vector<int>);

const int N = 1e3;
vector<int> g[N];
vector<int> order;

void dfs(int v) {
	order.push_back(v);
	for (int u : g[v]) {
		g[u].erase(find(all(g[u]), v));
		dfs(u);
	}
}

bool check(int pref) {
	vector<int> cur;
	for (int i = 0; i < pref; ++i) {
		cur.push_back(order[i] + 1);
	}
	return (bool)query(cur);
}

int findEgg(int n, vector<pair<int, int>> edges) {
	fill_n(g, n, vector<int>());
	for (auto e : edges) {
		--e.x, --e.y;
		g[e.x].push_back(e.y);
		g[e.y].push_back(e.x);
	}
	order.clear();
	dfs(0);
	int lef = 0, rig = (int)order.size();
	while (rig - lef > 1) {
		int mid = (lef + rig) / 2;
		if (check(mid)) {
			rig = mid;
		} else {
			lef = mid;
		}
	}
	return order[lef] + 1;
}

#ifdef LC
int n, s;
int query(vector<int> a) {
	cout << "query(" << a.size() << ")" << endl;
	for (int e : a) {
		cout << e << " ";
	}
	cout << endl;
	for (int e : a) {
		if (e == s) {
			return true;
		}
	}
	return false;
}
signed main() {
    assert(freopen("input.txt", "r", stdin));
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> s;
    vector<pair<int, int>> e;
    for (int v, u, i = 0; i < n - 1; ++i) {
    	cin >> v >> u;
    	e.emplace_back(v, u);
    }
    int ans = findEgg(n, e);
    cout << ans << endl;
    return 0;
}
#endif
# 결과 실행 시간 메모리 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 364 KB Number of queries: 4
4 Correct 1 ms 364 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 364 KB Number of queries: 8
2 Correct 17 ms 364 KB Number of queries: 9
3 Correct 20 ms 432 KB Number of queries: 9
4 Correct 20 ms 364 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 492 KB Number of queries: 9
2 Correct 17 ms 364 KB Number of queries: 9
3 Correct 21 ms 492 KB Number of queries: 9
4 Correct 20 ms 364 KB Number of queries: 9