#include<bits/stdc++.h>
using namespace std;
#include"grader.h"
#define N 1000
int id[N],sz;
vector<int> g[N];
void dfs(int s,int f){
id[++sz]=s;
for(auto x:g[s]){
if(x==f)continue;
dfs(x,s);
}
}
int findEgg(int n, vector<pair<int,int>> edge){
int i,l,r,mid,flag;
for(i=1;i<=n;i++)g[i].clear();
for(auto [a,b]:edge){
g[a].push_back(b);
g[b].push_back(a);
}
sz=0;
dfs(1,0);
vector<int> v;
l=1,r=n;
while(l<r){
mid=(l+r)/2;
for(i=l;i<=mid;i++)v.push_back(id[i]);
flag=query(v);
if(flag){
for(i=l;i<=mid;i++)v.pop_back();
r=mid;
}
else{
l=mid+1;
}
}
return id[r];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
348 KB |
Number of queries: 8 |
2 |
Correct |
12 ms |
352 KB |
Number of queries: 9 |
3 |
Correct |
14 ms |
620 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
336 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
336 KB |
Number of queries: 9 |
2 |
Correct |
13 ms |
372 KB |
Number of queries: 9 |
3 |
Correct |
14 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
336 KB |
Number of queries: 9 |