Submission #357673

# Submission time Handle Problem Language Result Execution time Memory
357673 2021-01-24T11:58:42 Z Mlxa Easter Eggs (info1cup17_eastereggs) C++14
0 / 100
3 ms 620 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 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
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 492 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 552 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 3 ms 620 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -