Submission #128627

# Submission time Handle Problem Language Result Execution time Memory
128627 2019-07-11T07:46:15 Z sheyasutaka Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
21 ms 436 KB
#include "grader.h"


#include <vector>
using std::vector;
using std::pair;
typedef pair<int, int> P;

vector<int> g[600];
vector<int> euler;

void dfs (int v, int p) {
	euler.push_back(v);

	for (int u : g[v]) {
		if (u == p) continue;
		dfs(u, v);
	}
}

int findEgg (int N, vector<P> bridges) {
	int i, j;

	for (i = 0; i < 600; i++) {
		g[i].clear();
	}
	euler.clear();

	for (i = 0; i < N - 1; i++) {
		g[bridges[i].first - 1].push_back(bridges[i].second - 1);
		g[bridges[i].second - 1].push_back(bridges[i].first - 1);
	}

	dfs(0, N);

	int l = 0, r = N;
	while (l + 1 < r) {
		int med = (l + r) / 2;

		vector<int> v;
		for (i = 0; i < med; i++) {
			v.push_back(euler[i] + 1);
		}
		if (query(v)) {
			r = med;
		} else {
			l = med;
		}
	}
	return euler[l] + 1;
}

Compilation message

eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:23:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Number of queries: 4
2 Correct 3 ms 248 KB Number of queries: 4
3 Correct 3 ms 248 KB Number of queries: 4
4 Correct 3 ms 376 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 7 ms 248 KB Number of queries: 8
2 Correct 14 ms 376 KB Number of queries: 9
3 Correct 20 ms 376 KB Number of queries: 9
4 Correct 16 ms 436 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 21 ms 376 KB Number of queries: 9
2 Correct 18 ms 376 KB Number of queries: 9
3 Correct 19 ms 376 KB Number of queries: 9
4 Correct 19 ms 376 KB Number of queries: 9