Submission #682023

# Submission time Handle Problem Language Result Execution time Memory
682023 2023-01-15T09:40:55 Z Mher777 Easter Eggs (info1cup17_eastereggs) C++17
100 / 100
21 ms 368 KB
#include <iostream>
#include <iomanip>
#include <array>
#include <string>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <list>
#include <iterator>
#include <numeric>
#include <complex>
#include <utility>
#include <random>
#include <fstream>
#include "grader.h"
using namespace std;

const int N = 600;

vector<int> g[N];
vector<int> a;

void dfs(int u, int num) {
	for (int i = 0; i < g[u].size(); i++) {
		if (g[u][i] != num) {
			a.push_back(g[u][i]);
			dfs(g[u][i], u);
		}
	}
}

int findEgg (int n, vector<pair<int,int>> b) {
	for (int i = 0; i < b.size(); i++) {
		g[b[i].first].push_back(b[i].second);
		g[b[i].second].push_back(b[i].first);
	}
	int l = 0, r = n - 1;
	a.push_back(1);
	dfs(1, -1);
	while (l < r) {
		int mid = (l + r) / 2;
		vector<int> v1;
		for (int i = 0; i <= mid; i++) {
			v1.push_back(a[i]);
		}
		if (query(v1)) {
			r = mid;
		}
		else {
			l = mid + 1;
		}
	}
	int ans = a[l];
	for (int i = 1; i <= n; i++) {
		g[i].clear();
	}
	a.clear();
	return ans;
}

Compilation message

eastereggs.cpp: In function 'void dfs(int, int)':
eastereggs.cpp:32:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   32 |  for (int i = 0; i < g[u].size(); i++) {
      |                  ~~^~~~~~~~~~~~~
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 0; i < b.size(); i++) {
      |                  ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 208 KB Number of queries: 4
2 Correct 1 ms 208 KB Number of queries: 4
3 Correct 1 ms 208 KB Number of queries: 4
4 Correct 1 ms 208 KB Number of queries: 4
# Verdict Execution time Memory Grader output
1 Correct 6 ms 336 KB Number of queries: 8
2 Correct 10 ms 356 KB Number of queries: 9
3 Correct 21 ms 360 KB Number of queries: 9
4 Correct 13 ms 336 KB Number of queries: 9
# Verdict Execution time Memory Grader output
1 Correct 19 ms 336 KB Number of queries: 9
2 Correct 13 ms 352 KB Number of queries: 9
3 Correct 15 ms 368 KB Number of queries: 9
4 Correct 13 ms 356 KB Number of queries: 9