#include <bits/stdc++.h>
#include "grader.h"
#define pb push_back
using namespace std;
vector<vector<int>> adj_list;
vector<int> dfs_order;
void dfs(int node, int par)
{
dfs_order.pb(node);
for (auto neigh : adj_list[node])
if (neigh != par)
dfs(neigh, node);
}
bool query(int i)
{
vector<int> v;
for (int j = 0; j <= i; j++)
v.pb(dfs_order[j] + 1);
return query(v);
}
int findEgg(int N, vector<pair<int, int>> bridges)
{
adj_list.resize(N);
for (int i = 0; i < N - 1; i++) {
adj_list[bridges[i].first - 1].pb(bridges[i].second - 1);
adj_list[bridges[i].second - 1].pb(bridges[i].first - 1);
}
dfs(0, -1);
int l = -1;
int r = N - 1;
while (r > l + 1) {
int mid = (l + r) / 2;
if (query(mid))
r = mid;
else
l = mid;
}
return dfs_order[r] + 1;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
270 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
187 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
187 ms |
131072 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |