# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88867 | sailormoon | Triumphal arch (POI13_luk) | C++14 | 1755 ms | 21692 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 <map>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <unordered_set>
using namespace std;
vector<vector<int>> graph (300001); // size
bool visited[300001];
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);
}
int main() {
int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
scanf("%d", &n);
cities = 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;
fill(visited, visited + cities, false);
if (canHandle(1, midpoint) == 0)
end = midpoint;
else
start = ++midpoint;
}
printf("%d\n", start);
return 0;
}
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... |