#include <bits/stdc++.h>
#include "grader.h"
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
};
template <typename T> bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
for (int i = 0; i < v.size(); i++) {
os << v[i] << (i + 1 == v.size() ? "\n" : " ");
}
return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
for (auto &e : t) {
fill_v(e, v);
}
};
vector<vector<int>> G;
vector<int> v, vis;
void dfs(int i, int p) {
v.push_back(i);
for (auto &e : G[i]) {
if (e == p) {
continue;
}
dfs(e, i);
v.push_back(i);
}
}
int findEgg(int N, vector<pair<int, int>> bridges) {
G.clear();
vis.clear();
v.clear();
G.resize(N);
vis.resize(N);
for (int i = 0; i < N - 1; i++) {
bridges[i].first--;
bridges[i].second--;
G[bridges[i].first].push_back(bridges[i].second);
G[bridges[i].second].push_back(bridges[i].first);
}
dfs(0, -1);
int l = 0, r = v.size();
int t = N;
while (1) {
if (t == 1) {
for (int i = l; i < r; i++) {
if (!vis[v[i]]) {
return v[i] + 1;
}
}
}
// cout << l << " " << r << " " << t << endl;
set<int> st;
int m = l;
for (int i = l; i < r; i++) {
if (!vis[v[i]]) {
st.insert(v[i]);
if (st.size() >= t / 2) {
m = i;
break;
}
}
}
vector<int> to;
for (auto it = st.begin(); it != st.end(); it++) {
to.push_back(*it + 1);
}
if (query(to)) {
for (int i = 0; i < N; i++) {
if (!st.count(i)) {
vis[i] = 1;
}
}
r = m + 1;
t = to.size();
} else {
for (int i = 0; i < N; i++) {
if (st.count(i)) {
vis[i] = 1;
}
}
l = m + 1;
t -= to.size();
}
}
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:86:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (st.size() >= t / 2) {
~~~~~~~~~~^~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
248 KB |
Number of queries: 4 |
2 |
Runtime error |
2 ms |
424 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
3 ms |
504 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
10 ms |
732 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
2 |
Halted |
0 ms |
0 KB |
- |