Submission #128612

# Submission time Handle Problem Language Result Execution time Memory
128612 2019-07-11T07:29:10 Z E869120 Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
21 ms 760 KB
#include <iostream>
#include <vector>
#include <algorithm>
#include "grader.h"
using namespace std;

vector<int> X[1 << 12], G;
bool used[1 << 12]; int N;

void dfs(int pos) {
	used[pos] = true; G.push_back(pos);
	for (int i = 0; i < X[pos].size(); i++) {
		if (used[X[pos][i]] == false) dfs(X[pos][i]);
	}
}

int solve(int cr) {
	cr = min(cr, N);
	vector<int>vec;
	for (int i = 0; i < cr; i++) vec.push_back(G[i]);
	return query(vec);
}

int findEgg(int NN, vector<pair<int, int>> bridges) {
	N = NN;
	for (int i = 0; i < bridges.size(); i++) {
		X[bridges[i].first].push_back(bridges[i].second);
		X[bridges[i].second].push_back(bridges[i].first);
	}
	dfs(1);

	int cx = 0, P = 8;
	if (NN <= 16) P = 3;
	for (int i = P; i >= 0; i--) {
		int v = solve(cx + (1 << i));
		if (v == 0) cx += (1 << i);
	}
	return G[cx];
}

Compilation message

eastereggs.cpp: In function 'void dfs(int)':
eastereggs.cpp:12:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < X[pos].size(); i++) {
                  ~~^~~~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:26:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < bridges.size(); i++) {
                  ~~^~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 3 ms 376 KB Number of queries: 4
2 Correct 3 ms 376 KB Number of queries: 4
3 Correct 2 ms 412 KB Number of queries: 4
4 Correct 2 ms 376 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 8 ms 632 KB Number of queries: 9
2 Correct 15 ms 504 KB Number of queries: 9
3 Correct 21 ms 696 KB Number of queries: 9
4 Correct 16 ms 576 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 21 ms 712 KB Number of queries: 9
2 Correct 18 ms 760 KB Number of queries: 9
3 Correct 16 ms 704 KB Number of queries: 9
4 Correct 19 ms 736 KB Number of queries: 9