#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int maxN = 515;
vector<int> kids[maxN];
vector<int> adj[maxN];
vector<int> sz(maxN);
vector<bool> in(maxN, true), vis(maxN, false);
void dfs(int v, int p) {
vis[v] = true;
for(int u : adj[v]) {
if (vis[u] || !in[u]) continue;
dfs(u, v);
kids[v].push_back(u);
sz[v] += sz[u];
}
}
vector<int> find_kids(int v) {
vector<int> ans;
ans.push_back(v);
for(int u : kids[v]) {
vector<int> f = find_kids(u);
for(int g : f) {
ans.push_back(g);
}
}
return ans;
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
fill(in.begin(), in.end(), true);
for(int i = 1; i <= N; i++) {
adj[i].clear();
}
for(auto i : bridges) {
adj[i.first].push_back(i.second);
adj[i.second].push_back(i.first);
}
int lg = ceil(log2(N));
int cc = N;
for(int i = 1; i <= 12; i++) {
fill(sz.begin(), sz.end(), 1);
fill(vis.begin(), vis.end(), false);
for(int j = 1; j <= N; j++) {
kids[j].clear();
}
for(int j = 1; j <= N; j++) {
if (in[j]) {
dfs(j, j);
break;
}
}
for(int j = 1; j <= N; j++) {
// cerr << j << " " << sz[j] << "\n";
if (sz[j] == ceil((double) cc / 2) && in[j]) {
vector<int> f = find_kids(j);
// for(int k : f) {
// cerr << k << " ";
// }
// cerr << "\n";
int ok = query(f);
// cerr << ok << "\n";
if (ok == 0) {
for(int k : f) {
in[k] = false;
}
} else {
fill(in.begin(), in.end(), false);
for(int k : f) {
in[k] = true;
}
}
break;
}
}
cc = 0;
for(int j = 1; j <= N; j++) {
cc += in[j];
}
// for(int j = 1; j <= N; j++) {
// cout << in[j] << " ";
// }
// cerr << cc << "\n\n";
}
int ans = -1;
for(int i = 1; i <= N; i++) {
if (in[i]) {
ans = i;
}
}
// assert(ans != -1);
return ans;
}
Compilation message
eastereggs.cpp: In function 'int findEgg(int, std::vector<std::pair<int, int> >)':
eastereggs.cpp:45:9: warning: unused variable 'lg' [-Wunused-variable]
45 | int lg = ceil(log2(N));
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
2 ms |
200 KB |
Number of queries: 12 |
2 |
Incorrect |
0 ms |
200 KB |
The found island is incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
7 ms |
328 KB |
Number of queries: 12 |
2 |
Incorrect |
6 ms |
328 KB |
The found island is incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Partially correct |
28 ms |
328 KB |
Number of queries: 12 |
2 |
Runtime error |
4 ms |
328 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |