#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];
int child[605], ma[605];
int par[605], head[605];
void dfs(ll u, ll t)
{
for(int i = 0; i < int(g[u].size()); ++i)
{
int 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(int 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)
{
int 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);
int pos = 0;
for(int i = 1; i <= n; ++i)
if(int(doan[i].size()) > 0)
{
if(query(doan[i]))
{
pos = i;
break;
}
}
int l = 0; int r = int(doan[pos].size())-1;
while(l < r)
{
int mid = (l+r+1)/2;
if(query(vector<int>(doan[pos].begin(), doan[pos].begin()+mid)))
r = mid-1;
else l = mid;
}
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 |
6 ms |
364 KB |
Number of queries: 9 |
2 |
Runtime error |
2 ms |
592 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
19 ms |
400 KB |
Number of queries: 10 |
2 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |