#include <bits/stdc++.h>
#include "grader.h"
#define pii pair<int,int>
#define ff first
#define ss second
#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;
bool vis[MAXN+1];
int sze[MAXN+1];
void init(int n, vector <pii> bridges) {
N = n;
for (int i = 1; i <= N; i++) {
path[i].clear();
vis[i] = false;
}
for (auto [a, b] : bridges) {
path[a].pb(b);
path[b].pb(a);
}
}
void dfs_sze(int now, int par) {
sze[now] = 1;
for (int i : path[now]) {
if (vis[i] || i == par) continue;
dfs_sze(i, now);
sze[now] += sze[i];
}
return;
}
int find_cen(int now, int par, int S) {
for (int i : path[now]) {
if (vis[i] || i == par) continue;
if (sze[i] * 2 > S)
return find_cen(i, now, S);
}
return now;
}
void dfs_get(int now, int par) {
qry.pb(now);
for (int i : path[now]) {
if (vis[i] || i == par) continue;
dfs_get(i, now);
}
}
int solve() {
int R = -1;
for (int i = 1; i <= N; i++) {
if (!vis[i]) {
dfs_sze(i, 0);
R = find_cen(i, 0, sze[i]);
break;
}
}
dfs_sze(R, 0);
if (sze[R] == 1) return R;
pii mxchd(0, -1);
for (int i : path[R]) {
if (vis[i]) continue;
mxchd = max(mxchd, pii(sze[i], i));
}
dfs_get(mxchd.ss, R);
bool flag = query(qry);
if (flag) {
for (int i = 1; i <= N; i++) vis[i] = true;
for (int i : qry) vis[i] = false;
} else {
for (int i : qry) vis[i] = true;
}
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:26:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
26 | for (auto [a, b] : bridges) {
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
2 |
Partially correct |
1 ms |
200 KB |
Number of queries: 5 |
3 |
Partially correct |
2 ms |
200 KB |
Number of queries: 9 |
4 |
Partially correct |
1 ms |
200 KB |
Number of queries: 15 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
328 KB |
Number of queries: 8 |
2 |
Partially correct |
9 ms |
328 KB |
Number of queries: 12 |
3 |
Partially correct |
15 ms |
328 KB |
Number of queries: 28 |
4 |
Runtime error |
2 ms |
456 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
328 KB |
Number of queries: 9 |
2 |
Partially correct |
10 ms |
328 KB |
Number of queries: 12 |
3 |
Partially correct |
16 ms |
328 KB |
Number of queries: 28 |
4 |
Runtime error |
2 ms |
456 KB |
Execution killed with signal 6 |