# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1124452 | gdragon | Easter Eggs (info1cup17_eastereggs) | C++20 | 0 ms | 0 KiB |
#include <bits/stdc++.h>
using namespace std;
#define TASK "long"
#define fi first
#define se second
#define ll long long
#define pb push_back
#define ALL(x) (x).begin(), (x).end()
#define GETBIT(mask, i) ((mask) >> (i) & 1)
#define MASK(i) ((1LL) << (i))
#define SZ(x) ((int)(x).size())
#define mp make_pair
#define CNTBIT(mask) __builtin_popcount(mask)
template<class X, class Y> bool maximize(X &x, Y y){ if (x < y) {x = y; return true;} return false;};
template<class X, class Y> bool minimize(X &x, Y y){ if (x > y) {x = y; return true;} return false;};
typedef pair<int, int> ii;
const int N = 1e5 + 5;
const int inf = 1e9 + 7;
const long long INF = (long long)1e18 + 7;
const int mod = 1e9 + 7;
void add(int &x, int y) {x += y; if (x >= mod) x -= mod;}
void sub(int &x, int y) {x -= y; if (x < 0) x += mod;}
int mul(int x, int y) {return 1LL * x * y % mod;}
// -----------------------------------------//
int n;
vector<int> adj[N];
int tin[N], node[N];
int timer = 0;
void dfs(int u, int p) {
tin[u] = ++timer;
node[timer] = u;
for(int v: adj[u]) if (v != p) {
dfs(v, u);
}
tout[u] = timer;
}
int findEgg(int N, vector<pair<int, int>> bridges) {
n = N;
for(auto [u, v]: bridges) {
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, -1);
vector<int> islands;
int l = 1, r = n, ans = -1;
while(l <= r) {
int mid = (l + r) >> 1;
while(SZ(islands) < mid) islands.push_back(node[SZ(islands) + 1]);
while(SZ(islands) > mid) islands.pop_back();
if (query(islands) == 1) {
ans = node[mid];
r = mid - 1;
}
else l = mid + 1;
}
return ans;
}