이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
int n;
const int maxn = 513;
vector <int> adj[maxn];
int sz[maxn];
bool there[maxn];
vector <int> sub[maxn];
void dfs(int u, int par = -1){
sz[u] = 1;
sub[u].clear();
sub[u].push_back(u);
for (int v : adj[u]){
if (v != par && there[v]){
dfs(v, u);
sz[u] += sz[v];
for (auto x : sub[v]) sub[u].push_back(x);
}
}
}
int findEgg (int N, vector <pair<int,int>> bridges)
{
n = N;
for (int i = 1; i <= n; i++) adj[i].clear();
for (auto [u, v] : bridges){
adj[u].push_back(v);
adj[v].push_back(u);
}
vector <int> poss;
for (int i = 1; i <= n; i++) {
poss.push_back(i);
there[i] = true;
}
while (poss.size() != 1){
n = poss.size();
bool found = false;
for (auto x : poss){
if (found) break;
dfs(x);
for (auto y : poss){
if (sz[y] == n / 2){
found = true;
vector <int> v1;
for (auto z : sub[y]) v1.push_back(z);
if (query(v1)){
poss = v1;
} else {
set <int> v2;
for (auto z : poss) v2.insert(z);
for (auto z : sub[y]) v2.erase(z);
poss.clear();
for (auto z : v2) poss.push_back(z);
}
break;
}
}
}
for (int i = 1; i <= n; i++) there[i] = false;
for (auto z : poss) there[z] = true;
assert(found);
}
return poss[0];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |