#include "grader.h"
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
using namespace std;
#ifdef LOCAL
#define eprintf(...) {fprintf(stderr, __VA_ARGS__);fflush(stderr);}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
const int N = 515;
vector<int> g[N];
vector<int> ord;
void AddEdge(int v, int u) {
g[v].push_back(u);
g[u].push_back(v);
}
void dfs(int v, int par) {
ord.push_back(v);
for (int u : g[v]) if (u != par) dfs(u, v);
}
int Ask(int x) {
vector<int> qv;
for (int i = 0; i <= x; i++)
qv.push_back(ord[i]);
return query(qv);
}
int findEgg(int n, vector<pii> bridges) {
for (int i = 1; i <= n; i++) g[i].clear();
for (int i = 0; i < n - 1; i++) {
AddEdge(bridges[i].fi, bridges[i].se);
}
ord.clear();
dfs(1, 0);
int l = 0, r = n - 1;
while (l < r) {
int mid = (l + r) >> 1;
if (Ask(mid))
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 |
1 ms |
208 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
356 KB |
Number of queries: 8 |
2 |
Correct |
11 ms |
352 KB |
Number of queries: 9 |
3 |
Correct |
17 ms |
352 KB |
Number of queries: 9 |
4 |
Correct |
19 ms |
336 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
368 KB |
Number of queries: 9 |
2 |
Correct |
13 ms |
352 KB |
Number of queries: 9 |
3 |
Correct |
15 ms |
340 KB |
Number of queries: 9 |
4 |
Correct |
16 ms |
340 KB |
Number of queries: 9 |