#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int nx=515;
int sz, t, cnt;
vector<int> qrs, on(nx), on2(nx), nd(nx), d[nx];
void dfs(int u, int p)
{
if (on[u]&&t>0) on2[u]=1, t--;
for (auto v:d[u]) if (v!=p) dfs(v, u);
}
void dfs2(int u, int p)
{
nd[u]=on2[u];
for (auto v:d[u]) if (v!=p) dfs2(v, u), nd[u]|=nd[v];
if (nd[u]) qrs.push_back(u);
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
for (int i=1; i<=N; i++) on[i]=1;
for (int i=0; i<N-1; i++) d[bridges[i].first].push_back(bridges[i].second), d[bridges[i].second].push_back(bridges[i].first);
cnt=0;
while (cnt++<=10)
{
sz=0;
for (int i=1; i<=N; i++) if (on[i]) sz++;
if (sz==1) for (int i=1; i<=N; i++) if (on[i]) return i;
qrs.clear();
for (int i=1; i<=N; i++) on2[i]=0, nd[i]=0;
t=sz/2;
dfs(1, 1);
dfs2(1, 1);
if (query(qrs)) for (int i=1; i<=N; i++) on[i]=on2[i];
else for (int i=1; i<=N; i++) on[i]=on[i]&&!on2[i];
}
return 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
1 ms |
452 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3072 ms |
340 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
3035 ms |
504 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |