#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(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 <= lg; 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] == 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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Number of queries: 4 |
2 |
Incorrect |
1 ms |
200 KB |
The found island is incorrect |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
328 KB |
Number of queries: 8 |
2 |
Runtime error |
1 ms |
328 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
34 ms |
704 KB |
Number of queries: 9 |
2 |
Runtime error |
1 ms |
328 KB |
Execution killed with signal 13 |
3 |
Halted |
0 ms |
0 KB |
- |