#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define db long double
#define ll long long
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define vll vector<pll>
#define endl '\n'
#define all(x) x.begin(), x.end()
#define fastio\
ios_base::sync_with_stdio(0);\
cin.tie(0);\
cout.tie(0)\
vi sub[550];
vi g[550];
bool used[550];
int dp[550], centroid, n;
void dfs(int node, int par){
dp[node] = 1;
for(int i : g[node]){
if(i == par) continue;
dfs(i, node);
dp[node] += dp[i];
}
bool f = true;
int s = 0;
for(int i : g[node]){
if(i == par) continue;
s += dp[i];
if(dp[i] > n / 2) f = false;
}
if(f and n - s <= n / 2) centroid = node;
}
void del(int node, int spec){
used[node] = true;
for(int i : g[node]){
if(i == spec or used[i]) continue;
del(i, node);
}
}
vi get(int node, int par){
vi v;
v.push_back(node);
for(int i : g[node]){
if(i == par or used[i]) continue;
vi tmp = get(i, node);
if(tmp.size() > v.size()) swap(tmp, v);
for(int i : tmp) v.push_back(i);
}
return v;
}
int findEgg(int N, vii bridges){
n = N;
for(int i = 1; i <= n; i++){
g[i].clear(), sub[i].clear(), used[i] = false, dp[i] = 0, centroid = 0;
}
for(pii i : bridges){
g[i.first].push_back(i.second);
g[i.second].push_back(i.first);
}
dfs(1, 1);
int cur = centroid, par = cur;
while(true){
int nxt = -1;
for(int i : g[cur]){
if(used[i]) continue;
vi v = get(i, cur);
if(query(v)){
nxt = i;
break;
}
}
if(nxt == -1) return cur;
del(cur, nxt);
cur = nxt;
}
return -1;
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:72:25: warning: unused variable 'par' [-Wunused-variable]
72 | int cur = centroid, par = cur;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
344 KB |
Number of queries: 9 |
2 |
Partially correct |
1 ms |
344 KB |
Number of queries: 8 |
3 |
Partially correct |
1 ms |
344 KB |
Number of queries: 9 |
4 |
Partially correct |
1 ms |
344 KB |
Number of queries: 15 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
500 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
2 ms |
796 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |