#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int N = 512;
//const int N = 1000;
int n;
vector<bool> vis;
vector<int> adj[N];
bool r[N];
int p[N];
int sz[N];
vector<int> q;
void dfs1(int u = 0, int par = -1) {
p[u] = par;
for (int &v : adj[u]) {
if (v == par) continue;
dfs1(v, u);
}
}
void dfs2(int u) {
vis[u] = 1;
sz[u] = 1;
for (int &v : adj[u]) {
if (v == p[u] || r[v]) continue;
if (!vis[v]) dfs2(v);
sz[u] += sz[v];
}
}
int findSubtree(int ssz) {
for (int i = 0; i < n; i++) {
if (!r[i] && sz[i] == ssz) return i;
}
return -1; // never reached
}
void fillQuery(int u) {
q.push_back(u+1);
for (int &v : adj[u]) {
if (v == p[u] || r[v]) continue;
fillQuery(v);
}
}
int findEgg (int N, vector < pair < int, int > > bridges)
{
n = N;
for (int i = 0; i < n; i++) {
r[i] = 0;
adj[i].clear();
}
for (auto &[x, y] : bridges) {
adj[x-1].push_back(y-1);
adj[y-1].push_back(x-1);
}
dfs1();
int x = n;
while (x != 1) {
vis.clear();
vis.resize(n, 0);
for (int i = 0; i < n; i++) {
if (vis[i] || r[i]) continue;
dfs2(i);
}
int mid = x/2;
int u = findSubtree(mid);
/*
if (u == -1) {
mid++;
u = findSubtree(mid);
}
*/
q.clear();
fillQuery(u);
if (query(q)) {
for (int i = 0; i < n; i++) {
r[i] = 1;
}
for (int &i : q) r[i-1] = 0;
x = mid;
}
else {
for (int &i : q) r[i-1] = 1;
x -= mid;
}
}
vis.clear();
vis.resize(n, 0);
for (int i = 0; i < n; i++) {
if (vis[i] || r[i]) continue;
dfs2(i);
}
return findSubtree(1) + 1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
208 KB |
Number of queries: 4 |
2 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
336 KB |
Number of queries: 8 |
2 |
Runtime error |
1 ms |
464 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
10 ms |
336 KB |
Number of queries: 9 |
2 |
Runtime error |
1 ms |
476 KB |
Execution killed with signal 6 |
3 |
Halted |
0 ms |
0 KB |
- |