#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e9+7;
const ll MOD = 998244353;
typedef pair<ll,ll> ii;
#define iii pair<ll,ii>
#define f(i,a,b) for(ll i = a;i < b;i++)
#define pb push_back
#define vll vector<ll>
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
///I hope I will get uprating and don't make mistakes
///I will never stop programming
///sqrt(-1) Love C++
///Please don't hack me
///@TheofanisOrfanou Theo830
///Think different approaches (bs,dp,greedy,graphs,shortest paths,mst)
///Stay Calm
///Look for special cases
///Beware of overflow and array bounds
///Think the problem backwards
///Training
#include "grader.h"
vector<vector<ll> >adj;
ll arr[600];
ll tim = 0;
void dfs(ll idx,ll p){
arr[tim] = idx;
tim++;
for(auto x:adj[idx]){
if(x != p){
dfs(x,idx);
}
}
}
int findEgg(int N, vector < pair < int, int > > bridges){
adj.assign(N+5,vector<ll>());
tim = 0;
for(auto x:bridges){
adj[x.F].pb(x.S);
adj[x.S].pb(x.F);
}
dfs(1,0);
ll l = 0,r = N-1;
ll ans = r;
while(l <= r){
ll mid = (l+r)/2;
vector<int>exo;
if(l == ans){
break;
}
f(i,0,mid + 1){
exo.pb(arr[i]);
}
if(query(exo)){
r = mid - 1;
ans = min(ans,mid);
}
else{
l = mid + 1;
}
}
return arr[ans];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
200 KB |
Number of queries: 4 |
2 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
3 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
4 |
Correct |
1 ms |
200 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
332 KB |
Number of queries: 8 |
2 |
Correct |
12 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
15 ms |
340 KB |
Number of queries: 9 |
4 |
Correct |
22 ms |
408 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
23 ms |
388 KB |
Number of queries: 9 |
2 |
Correct |
13 ms |
356 KB |
Number of queries: 9 |
3 |
Correct |
13 ms |
356 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
356 KB |
Number of queries: 9 |