Submission #88838

#TimeUsernameProblemLanguageResultExecution timeMemory
88838zvikiTriumphal arch (POI13_luk)C++14
0 / 100
447 ms29472 KiB
#include <iostream> #include <algorithm> #include <vector> #include <set> #define avg(a ,b) ((a + b) / 2) using namespace std; vector<vector<int>> map_of_cities; int num_not_satisfy(set<int> & visited_set, int num_workers, int city) { int i, child_city, num_children = map_of_cities[city].size(), rec_res; visited_set.insert(city); for (i = 0, rec_res = 0; i < num_children; i++) { child_city = map_of_cities[city][i]; if (visited_set.find(child_city) != visited_set.end()) { rec_res += num_not_satisfy(visited_set, num_workers, child_city); } } if (num_children + rec_res < num_workers) { return 0; } else { return num_children + rec_res - num_workers; } } int main() { int n, i, res, bsearch_start, bsearch_end, bsearch_mid, road_from, road_to; cin >> n; for (i = 0; i < n; i++) { vector<int> temp; map_of_cities.push_back(temp); } for (i = 1; i < n; i++) { cin >> road_from >> road_to; map_of_cities[road_from - 1].push_back(road_to - 1); map_of_cities[road_to - 1].push_back(road_from - 1); } bsearch_start = 0, bsearch_end = n; for (; bsearch_start < bsearch_end; ) { bsearch_mid = avg(bsearch_start, bsearch_end); set<int> visited_set; res = num_not_satisfy(visited_set, bsearch_mid, 0); if (res != 0) { bsearch_start = bsearch_mid + 1; } else { bsearch_end = bsearch_mid; } } res = bsearch_start; cout << res << endl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...