# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
88875 | sailormoon | 새로운 문제 (POI13_luk) | C++14 | 1381 ms | 87728 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
int canHandle(int v, int crs);
vector<vector<int>> graph (3000001); // size
bool visited[3000001];
int main() {
int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
scanf("%d", &n);
cities = n; // for further usage
end = n; // last point
n--;
while (n--) {
scanf("%d %d", &a, &b);
graph[a].push_back(b);
graph[b].push_back(a);
}
// binary search for sufficient amount of crews
while (start < end) {
midpoint = (start + end) / 2;
for (int i = 0; i < cities; i++) visited[i] = false; // clear array
if (canHandle(1, midpoint) == 0)
end = midpoint;
else
start = ++midpoint;
}
printf("%d\n", start);
return 0;
}
int canHandle(int v, int crs) {
int num_children = 0, need_crews = 0;
visited[v] = true;
for (int i = 0; i < graph[v].size(); i++) {
if (!visited[graph[v][i]]) {
num_children++;
need_crews += canHandle(graph[v][i], crs);
}
}
return max(0, num_children + need_crews - crs);
}
컴파일 시 표준 에러 (stderr) 메시지
# | 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... |