#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int MAXN = 600;
vector<int> adj[MAXN];
int pre[MAXN];
int t = 0;
void dfs(int v, int p){
pre[v] = ++ t;
for(auto u : adj[v]) if(u != p) dfs(u, v);
}
bool ask(int l, int r, int n){
vector<int> islands;
for(int i=1; i<=n; i++){
if(l <= pre[i] && pre[i] <= r){
islands.push_back(i);
}
}
return query(islands);
}
int compute(int l, int r, int n){
if(l == r) return l;
int m = l + (r - l) / 2;
if(ask(l, m, n)) return compute(l, m, n);
return compute(m + 1, r, n);
}
int findEgg(int n, vector<pair<int, int>> bridges){
t = 0;
for(int i=1; i<=n; i++) adj[i].clear();
for(auto [a, b] : bridges){
adj[a].push_back(b);
adj[b].push_back(a);
}
dfs(1, 1);
int x = compute(1, n, n);
for(int i=1; i<=n; i++){
if(pre[i] == x){
return i;
}
}
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
65 | }
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
336 KB |
Number of queries: 4 |
2 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
592 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
4 ms |
592 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |