# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88910 | sailormoon | Triumphal arch (POI13_luk) | C++14 | 1215 ms | 39484 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int can_handle(int v, int crs, bool visited[]);
vector<vector<int>> graph (1000001); // size
int main() {
int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
scanf("%d", &n);
end = n; // last point
for (int i = 1; i < n; i++) {
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) {
bool visited[1000001];
midpoint = (start + end) / 2;
for (int i = 1; i <= n; i++) visited[i] = false; // clear array
if (can_handle(1, midpoint, visited) == 0) end = midpoint;
else start = ++midpoint;
}
printf("%d\n", start);
return 0;
}
int can_handle(int v, int crs, bool visited[]) {
int num_children = 0, need_crews = 0;
visited[v] = true;
for (int i = 0; i < graph[v].size(); i++) {
int cur = graph[v][i];
if (!visited[cur]) {
num_children++;
need_crews += can_handle(cur, crs, visited);
}
}
if (num_children + need_crews - crs <= 0)
return 0;
return num_children + need_crews - crs;
}
Compilation message (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... |