# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
89331 | vvash17 | Triumphal arch (POI13_luk) | C++14 | 0 ms | 0 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>
using namespace std;
vector<int> graph[300001];
int city_num,from,to;
int evaluate_result(int &search_start,int &need_num,int* been_there){
int available_neigbours = 0;
int sub_tree_res = 0;
been_there[search_start]++;
int neighbour_size = graph[search_start].size();
for(int i = 0; i<neighbour_size; i++){
int tmp = graph[search_start][i];
if(been_there[tmp] == 0){
available_neigbours++;
sub_tree_res += evaluate_result(tmp,need_num,been_there);
}
}
int res = available_neigbours-(need_num-sub_tree_res);
if(res < 0)return 0;
return res;
}
int search_init(int &need_num){
int been_there[city_num+1] = {0};
int start = 1;
return evaluate_result(start,need_num,been_there);
}
int main() {
cin>>city_num;
for(int i = 1; i<city_num; i++){
cin>>from>>to;
graph[from].push_back(to);
graph[to].push_back(from);
}
int tmp;
int start_point = 1;
int finish_point = city_num;
int result = 0;
while (start_point < finish_point) {
tmp = (start_point+finish_point)/2;
result = search_init(need_num);
if(result == 0){
finish_point = tmp;
}else{
start_point = ++tmp;
}
result = start_point;
}
cout<<result<<endl;
return 0;
}