# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
88865 | 123456 | Triumphal arch (POI13_luk) | C++14 | 1635 ms | 17592 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 <iostream>
#include <vector>
#include <algorithm>
using namespace std;
vector<vector<int>> graph;
vector<bool> visited;
int check(int currentCity, int k) {
int childrenSum = 0;
visited[currentCity] = true;
for (int i = 0; i < graph[currentCity].size(); i++) {
if (!visited[graph[currentCity][i]]) {
childrenSum += check(graph[currentCity][i], k);
}
}
int numberOfChildren = graph[currentCity].size() - 1;
if (currentCity == 0) numberOfChildren++;
return max(0, numberOfChildren + childrenSum - k);
}
int main() {
int numberOfTowns;
cin >> numberOfTowns;
if (numberOfTowns < 0) {
return 0;
}
visited.resize(numberOfTowns);
graph.resize(numberOfTowns);
for (int i = 0; i < numberOfTowns - 1; i++) {
int a, b;
cin >> a >> b;
a--;
b--;
graph[a].push_back(b);
graph[b].push_back(a);
}
int start = 1;
int end = numberOfTowns;
int currentK;
while (start < end) {
for (int i = 0; i < numberOfTowns; i++) {
visited[i] = false;
}
currentK = (start + end) / 2;
if (!check(0, currentK)) {
start = currentK + 1;
}
else {
end = currentK;
}
}
cout << start << endl;
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... |