#include <bits/stdc++.h>
#include "grader.h"
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << "LINE(" << __LINE__ << "): " << #x << " is " << x << endl
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
const int INF = 1e9 + 7, N = 520;
vi G[N];
int vis[N], sz[N], tot;
void init(int n) {
for(int i = 1; i <= n; i++) {
G[i].clear();
vis[i] = 0;
}
}
int dfs_sz(int u, int p = 0) {
sz[u] = 1;
for(int v:G[u]) if(v != p && !vis[v]) {
sz[u] += dfs_sz(v, u);
}
return sz[u];
}
pi c;
void get_c(int u, int p = 0) {
for(int v:G[u]) if(v != p && !vis[v]) {
if(abs(sz[v] - (tot - sz[v])) <= 1) {
c = {u, v};
}
get_c(v, u);
}
}
vi s;
void dfs(int u, int p) {
s.PB(u);
for(int v:G[u]) if(v != p && !vis[v]) dfs(v, u);
}
int go(int u) {
tot = dfs_sz(u);
if(tot == 1) return u;
get_c(u);
int x = c.F, y = c.S;
//cerr << x << ", " << y << endl;
s.clear();
dfs(y, x);
if(query(s)) {
vis[x] = 1;
return go(y);
} else {
vis[y] = 1;
return go(x);
}
}
int findEgg(int n, V<pi> es) {
init(n);
for(pi p:es) G[p.F].PB(p.S), G[p.S].PB(p.F);
return go(1);
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Number of queries: 4 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
328 KB |
Number of queries: 8 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
328 KB |
Number of queries: 9 |
2 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |