이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "grader.h"
using namespace std;
typedef pair < int, int > PII;
const int NMAX = ((1 << 9) + 5);
const int ROOT = 1;
const int INF = 1e9;
vector < int > G[NMAX];
int W[NMAX], Size, centroid, ans;
bool used[NMAX];
vector < int > V;
bitset < NMAX > Sel;
inline void Add_Edge (int X, int Y)
{
G[X].push_back(Y), G[Y].push_back(X);
return;
}
inline void Reset (int N)
{
ans = 0;
for(int i = 1; i <= N; ++i)
used[i] = 0, W[i] = 0, G[i].clear();
return;
}
inline void DFS_1 (int Node)
{
W[Node] = 1, Sel[Node] = 1;
for(auto it : G[Node])
if(!used[it] && !Sel[it])
{
DFS_1(it);
W[Node] += W[it];
}
return;
}
inline int MAX (int a, int b)
{
return ((a > b) ? a : b);
}
inline PII Find (int Node)
{
int Max = Size - W[Node];
PII ans = {0, INF};
Sel[Node] = 1;
for(auto it : G[Node])
if(!used[it] && !Sel[it])
{
Max = MAX(Max, W[it]);
PII curr = Find(it);
if(curr.second < ans.second)
ans = curr;
}
if(Max < ans.second)
ans = {Node, Max};
return ans;
}
inline void DFS_2 (int Node)
{
V.push_back(Node);
Sel[Node] = 1;
for(auto it : G[Node])
if(!used[it] && !Sel[it])
DFS_2(it);
return;
}
inline void Go (int Node)
{
if(ans)
return;
Sel.reset(), DFS_1(Node), Size = W[Node];
Sel.reset();
int centroid = Find(Node).first;
used[centroid] = 1;
V.clear(), V.push_back(centroid);
if(query(V))
{
ans = centroid;
return;
}
for(auto it : G[centroid])
if(!used[it] && !ans)
{
V.clear(), Sel.reset();
DFS_2(it);
if(query(V))
{
Go(it);
return;
}
}
return;
}
int findEgg (int N, vector < PII > edges)
{
Reset(N);
for(auto it : edges)
Add_Edge(it.first, it.second);
Go(ROOT);
return ans;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |