#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define fi first
#define se second
#define ll long long
vector< vector<int> > g;
vector<int> doan[605];
ll child[605], ma[605];
ll par[605], head[605];
void dfs(ll u, ll t)
{
for(int i = 0; i < int(g[u].size()); ++i)
{
ll v = g[u][i];
if(v == t) continue;
par[v] = u;
dfs(v, u);
if(child[v]+1 > child[u])
{
child[u] = child[v]+1;
ma[u] = v;
}
}
}
void hld(ll u)
{
if(ma[par[u]] == u) head[u] = head[par[u]];
else head[u] = u;
doan[head[u]].push_back(u);
if(ma[u] > 0) hld(ma[u]);
for(int i = 0; i < int(g[u].size()); ++i)
{
ll v = g[u][i];
if(v != par[u] && v != ma[u]) hld(v);
}
}
int findEgg (int n, vector < pair < int, int > > bridges)
{
g.clear();
for(int i = 1; i <= 600; ++i)
doan[i].clear();
g.resize(n+1);
for(int i = 0; i < int(bridges.size()); ++i)
{
g[bridges[i].fi].push_back(bridges[i].se);
g[bridges[i].se].push_back(bridges[i].fi);
}
dfs(1, 0);
hld(1);
ll pos = 0;
for(int i = 1; i <= n; ++i)
if(int(doan[i].size()) > 0)
{
if(query(doan[i]))
{
pos = i;
break;
}
}
ll l = 0; ll r = int(doan[pos].size())-1;
while(l < r)
{
ll mid = (l+r)/2;
if(query(vector<int>(doan[pos].begin(), doan[pos].begin()+mid+1)))
r = mid;
else l = mid+1;
}
return doan[pos][l];
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
1 ms |
208 KB |
Number of queries: 5 |
2 |
Partially correct |
1 ms |
208 KB |
Number of queries: 8 |
3 |
Partially correct |
2 ms |
208 KB |
Number of queries: 12 |
4 |
Partially correct |
1 ms |
208 KB |
Number of queries: 14 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
336 KB |
Number of queries: 9 |
2 |
Runtime error |
2 ms |
500 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
26 ms |
416 KB |
Number of queries: 10 |
2 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |