#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];
}
int get_c(int u, int p = 0) {
int mx = 0;
for(int v:G[u]) if(v != p && !vis[v]) {
int cc = get_c(v, u);
mx = max(mx, sz[v]);
if(cc) return cc;
}
if(max(mx, tot - sz[u]) * 2 <= tot) return u;
return 0;
}
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);
int c = get_c(u);
for(int v:G[c]) if(!vis[v]) {
s.clear();
dfs(v, c);
if(query(s)) {
vis[c] = 1;
return go(v);
}
}
return c;
}
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 |
Partially correct |
2 ms |
308 KB |
Number of queries: 7 |
2 |
Partially correct |
2 ms |
204 KB |
Number of queries: 8 |
3 |
Partially correct |
1 ms |
200 KB |
Number of queries: 9 |
4 |
Partially correct |
2 ms |
200 KB |
Number of queries: 15 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
4 ms |
328 KB |
Number of queries: 13 |
2 |
Partially correct |
10 ms |
328 KB |
Number of queries: 29 |
3 |
Partially correct |
18 ms |
328 KB |
Number of queries: 39 |
4 |
Runtime error |
2 ms |
456 KB |
Execution killed with signal 6 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
19 ms |
328 KB |
Number of queries: 15 |
2 |
Partially correct |
15 ms |
328 KB |
Number of queries: 22 |
3 |
Partially correct |
20 ms |
328 KB |
Number of queries: 40 |
4 |
Runtime error |
2 ms |
472 KB |
Execution killed with signal 6 |