이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
const int MAXN = 520;
set<int> g[MAXN];
int n, sub[MAXN];
vector<int> cenTree[MAXN], what[MAXN];
int dfs(int u,int p){
sub[u] = 1;
for(auto v:g[u]) if(v != p){
sub[u] += dfs(v, u);
}
return sub[u];
}
int centroid(int u, int p, int mx){
for(auto v:g[u]) if(v != p){
if(sub[v] > (mx / 2)) return centroid(v, u, mx);
}
return u;
}
void make(int u, int p){
int mx = dfs(u, p);
int c = centroid(u, p, mx);
if(p == 0) p = c;
else{
cenTree[p].push_back(c);
cenTree[c].push_back(p);
}
vector<int> temp(g[c].begin(), g[c].end());
for(auto v:temp){
g[c].erase(v);
g[v].erase(c);
make(v, c);
}
}
void dfs2(int u,int p){
what[u].push_back(u);
for(auto v:cenTree[u]) if(v != p){
dfs2(v, u);
for(auto x:what[v]) what[u].push_back(x);
}
}
int get(int u,int p){
// cout << "u : " << u << "\n";
for(auto v:cenTree[u]) if(v != p){
// cout << "v: " << v << " ";
int q = query(what[v]);
// cout << "what : ";
// for(auto gg:what[v]) cout << gg << " ";
// cout << "\n";
if(q == 1){
// cout << "lololl\n";
// for(auto lol:what[v]) cout << lol << " ";
// cout << "\n";
return get(v, u);
}
}
return u;
}
int findEgg (int N, vector < pair < int, int > > bridges){
n = N;
for(int i = 0;i < N-1;i++){
int u = bridges[i].first;
int v = bridges[i].second;
g[u].insert(v);
g[v].insert(u);
}
make(1, 0);
dfs2(1, 0);
// for(int i =1;i <= n;i++){
// cout << i << "-> ";
// for(auto u:cenTree[i]) cout << u << " ";
// cout << "\n";
// }
return get(1, 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... |