#include "grader.h"
#include <bits/stdc++.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(512);
vector<int> v, vis(512);
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) {
for (int i = 0; i < 512; i++) {
G[i].clear();
vis[i] = 0;
}
v.clear();
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 (t > 1) {
// cout << l << " " << r << " " << t << endl;
set<int> st;
int m, s;
for (int i = l; i < r; i++) {
if (vis[v[i]] == 0) {
st.insert(v[i]);
if (st.size() > t / 2) {
m = i;
s = st.size();
break;
}
}
}
s--;
vector<int> to;
for (int i = l; i < m; i++) {
to.push_back(v[i] + 1);
}
sort(all(to));
to.erase(unique(all(to)), to.end());
if (query(to)) {
for (int i = m; i < r; i++) {
if (st.count(v[i]) == 0) {
vis[v[i]] = 1;
}
}
r = m;
t = s;
} else {
for (int i = l; i < m; i++) {
vis[v[i]] = 1;
}
l = m;
t -= s;
}
if (t == 1) {
for (int i = l; i < r; i++) {
if (!vis[v[i]]) {
return v[i] + 1;
}
}
}
}
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:80:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
if (st.size() > t / 2) {
~~~~~~~~~~^~~~~~~
eastereggs.cpp:117:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
eastereggs.cpp:87:10: warning: 's' may be used uninitialized in this function [-Wmaybe-uninitialized]
s--;
~^~
eastereggs.cpp:76:13: warning: 'm' may be used uninitialized in this function [-Wmaybe-uninitialized]
int m, s;
^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
248 KB |
Number of queries: 4 |
2 |
Correct |
2 ms |
248 KB |
Number of queries: 4 |
3 |
Correct |
3 ms |
248 KB |
Number of queries: 4 |
4 |
Correct |
3 ms |
376 KB |
Number of queries: 4 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
376 KB |
Number of queries: 8 |
2 |
Correct |
14 ms |
248 KB |
Number of queries: 9 |
3 |
Correct |
20 ms |
376 KB |
Number of queries: 9 |
4 |
Correct |
14 ms |
248 KB |
Number of queries: 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
19 ms |
376 KB |
Number of queries: 9 |
2 |
Correct |
21 ms |
248 KB |
Number of queries: 9 |
3 |
Correct |
21 ms |
248 KB |
Number of queries: 9 |
4 |
Correct |
18 ms |
376 KB |
Number of queries: 9 |