#include <bits/stdc++.h>
#include "grader.h"
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;
const int N = 512;
vector<int> A[N];
int ord[N];
void dfs(int v, int p, int &t)
{
ord[t++] = v;
for (int u : A[v])
if (u != p)
dfs(u, v, t);
}
int qry(int r)
{
vector<int> q;
Loop (i,0,r)
q.push_back(ord[i]);
return query(q);
}
int findEgg(int N, vector<pair<int, int>> bridges)
{
Loop (i,1,N+1)
A[i].clear();
Loop (i,0,N-1) {
auto [v, u] = bridges[i];
A[v].push_back(u);
A[u].push_back(v);
}
dfs(1, -1, *new int(0));
int l = 0, r = N-1;
while (l < r) {
int mid = (l+r)/2;
if (qry(mid+1))
r = mid;
else
l = mid+1;
}
return ord[l];
}
# |
결과 |
실행 시간 |
메모리 |
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 |
2 ms |
208 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
340 KB |
Number of queries: 8 |
2 |
Correct |
12 ms |
340 KB |
Number of queries: 9 |
3 |
Correct |
22 ms |
336 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
352 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |