#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
#define REP(i, j, k) for (int i = (j); i < (k); i++)
#define RREP(i, j, k) for (int i = (j); i >= (k); i--)
template <class T>
inline bool mnto(T &a, const T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T &a, const T b) {return a < b ? a = b, 1 : 0;}
typedef long long ll;
typedef long double ld;
#define FI first
#define SE second
typedef pair<int, int> ii;
typedef pair<ll, ll> pll;
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int) x.size()
#define pb push_back
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
#ifndef DEBUG
#define cerr if (0) cerr
#endif
const int INF = 1000000005;
const ll LINF = 1000000000000000005;
const int MAXN = 600;
int n;
vi adj[MAXN];
bool guilty[MAXN], vis[MAXN];
int findEgg (int N, vii bridges) {
n = N;
REP (i, 1, n + 1) {
adj[i].clear();
}
REP (i, 0, n - 1) {
auto [u, v] = bridges[i];
adj[u].pb(v);
adj[v].pb(u);
}
REP (i, 1, n + 1) {
guilty[i] = 1;
}
while (1) {
queue<int> bfs;
bfs.push(1);
int all = 0;
REP (i, 1, n + 1) {
all += guilty[i];
vis[i] = 0;
}
if (all == 1) {
break;
}
int cnt = 0;
while (!bfs.empty()) {
int u = bfs.front(); bfs.pop();
vis[u] = 1;
cnt += guilty[u];
if (cnt >= all / 2) {
break;
}
for (int v : adj[u]) {
if (vis[v]) {
continue;
}
bfs.push(v);
}
}
vi qry;
cerr << "QUERY: ";
REP (i, 1, n + 1) {
if (vis[i]) {
qry.pb(i);
cerr << i << ' ';
}
}
cerr << '\n';
bool res = query(qry);
cerr << "RETURN: " << res << '\n';
REP (i, 1, n + 1) {
if (guilty[i]) {
guilty[i] ^= res ^ vis[i];
}
}
}
REP (i, 1, n + 1) {
if (guilty[i]) {
return i;
}
}
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, vii)':
eastereggs.cpp:101:1: warning: control reaches end of non-void function [-Wreturn-type]
101 | }
| ^
# |
Verdict |
Execution time |
Memory |
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 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
384 KB |
Number of queries: 8 |
2 |
Correct |
14 ms |
336 KB |
Number of queries: 9 |
3 |
Correct |
15 ms |
348 KB |
Number of queries: 9 |
4 |
Correct |
13 ms |
336 KB |
Number of queries: 9 |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
348 KB |
Number of queries: 9 |
2 |
Correct |
11 ms |
344 KB |
Number of queries: 9 |
3 |
Correct |
12 ms |
476 KB |
Number of queries: 9 |
4 |
Correct |
15 ms |
336 KB |
Number of queries: 9 |