이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*************************************************************************
* *
* XX Olimpiada Informatyczna *
* *
* Zadanie: Luk triumfalny *
* Autor: Karol Pokorski *
* Zlozonosc czasowa: O(n log n) *
* Zlozonosc pamieciowa: O(n) *
* Opis: Rozwiazanie wzorcowe *
* *
*************************************************************************/
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
const int MAXN = 1000001;
vector<int> adj[MAXN];
bool visited[MAXN];
int Check(int u, int k) {
int numChildren = 0, sumTree = 0;
visited[u] = true;
for (int i = 0; i < (int)adj[u].size(); i++)
if (!visited[adj[u][i]]) {
numChildren++;
sumTree += Check(adj[u][i], k);
}
return max(0, numChildren+sumTree-k);
}
int main() {
int ret, N, fromSearch = 0, toSearch;
ret = scanf("%d", &N);
if (ret < 0)
return 0;
for (int i = 0; i < N-1; i++) {
int u, v;
ret = scanf("%d%d", &u, &v);
u--;
v--;
adj[u].push_back(v);
adj[v].push_back(u);
}
toSearch = N;
while (fromSearch < toSearch) {
int centSearch = (fromSearch+toSearch)/2;
fill(visited, visited+N, false);
if (Check(0, centSearch) == 0)
toSearch = centSearch;
else
fromSearch = centSearch+1;
}
printf("%d\n", fromSearch);
return 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |