#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);
void dfs(int v, int p) {
for(int u : adj[v]) {
if (u == p || !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)
{
for(auto i : bridges) {
adj[i.first].push_back(i.second);
adj[i.second].push_back(i.first);
}
int lg = ceil(log2(N));
for(int i = 1; i <= lg; i++) {
sz.assign(maxN, 1);
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++) {
if (sz[j] == N / (1<<i)) {
vector<int> f = find_kids(j);
bool ok = query(f);
if (!ok) {
for(int k : f) {
in[k] = false;
}
} else {
fill(in.begin(), in.end(), false);
for(int k : f) {
in[k] = true;
}
}
}
}
}
int ans = -1;
for(int i = 1; i <= N; i++) {
if (in[i]) {
ans = i;
}
}
// assert(ans != -1);
return ans;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
1 ms |
456 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
2 ms |
656 KB |
Execution killed with signal 6 |
2 |
Halted |
0 ms |
0 KB |
- |