답안 #389338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
389338 2021-04-14T03:12:34 Z casperwang Easter Eggs (info1cup17_eastereggs) C++14
100 / 100
39 ms 456 KB
#include <bits/stdc++.h>
#include "grader.h"
#define pii pair<int,int>
#define ff first
#define ss second
#define All(x) x.begin(), x.end()
#define pb push_back
using namespace std;
#define debug(args...) kout("[ " + string(#args) + " ]", args)
void kout() { cerr << endl; }
template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); }
template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; }

const int MAXN = 512;
int N;
vector <int> path[MAXN+1];
vector <int> qry;
set <int> can;
int qry_sze;

void init(int n, vector <pii> bridges) {
	N = n;
	can.clear();
	for (int i = 1; i <= N; i++) {
		path[i].clear();
		can.insert(i);
	}
	for (auto [a, b] : bridges) {
		path[a].pb(b);
		path[b].pb(a);
	}
}

void dfs_get(int now, int par) {
	if (qry_sze * 2 >= can.size()) return;
	qry.pb(now);
	if (can.find(now) != can.end()) qry_sze++;
	for (int i : path[now]) {
		if (i == par) continue;
		dfs_get(i, now);
	}
}

int solve() {
	if (can.size() == 1) return *can.begin();
	qry_sze = 0;
	dfs_get(*can.begin(), 0);
	bool flag = query(qry);
	qry.pb(N+1);
	if (flag) {
		set <int> tmp;
		for (int i : qry) if (can.find(i) != can.end()) tmp.insert(i);
		can = tmp;
	} else {
		for (int i : qry) can.erase(i);
	}
	qry.clear();
	return solve();
}

int findEgg (int n, vector <pii> bridges) {
	init(n, bridges);
	return solve();
}

Compilation message

eastereggs.cpp: In function 'void init(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:28:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   28 |  for (auto [a, b] : bridges) {
      |            ^
eastereggs.cpp: In function 'void dfs_get(int, int)':
eastereggs.cpp:35:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::set<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   35 |  if (qry_sze * 2 >= can.size()) return;
      |      ~~~~~~~~~~~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 200 KB Number of queries: 4
2 Correct 1 ms 200 KB Number of queries: 4
3 Correct 2 ms 200 KB Number of queries: 4
4 Correct 1 ms 200 KB Number of queries: 4
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 352 KB Number of queries: 8
2 Correct 13 ms 360 KB Number of queries: 9
3 Correct 24 ms 456 KB Number of queries: 9
4 Correct 26 ms 368 KB Number of queries: 9
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 456 KB Number of queries: 9
2 Correct 28 ms 356 KB Number of queries: 9
3 Correct 30 ms 456 KB Number of queries: 9
4 Correct 39 ms 332 KB Number of queries: 9