Submission #88894

#TimeUsernameProblemLanguageResultExecution timeMemory
88894sailormoonTriumphal arch (POI13_luk)C++14
0 / 100
310 ms34264 KiB
#include <string> #include <algorithm> #include <iostream> #include <vector> using namespace std; int canHandle(int crs, int v); vector<vector<int>> graph (1000001); // size bool visited[1000001]; 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) { midpoint = (start + end) / 2; for (int i = 0; i < n; i++) visited[i] = false; // clear array if (canHandle(midpoint, 1) == 0) end = midpoint; else start = midpoint + 1; } printf("%d\n", start); return 0; } int canHandle(int crs, int v) { int num_children = 0, need_crews = 0; visited[v] = true; for (int i = 0; i < (int) graph[v].size(); i++) { if (!visited[graph[v][i]]) { num_children++; need_crews += canHandle(graph[v][i], crs); } } if (num_children + need_crews - crs <= 0) return 0; return num_children + need_crews - crs; }

Compilation message (stderr)

luk.cpp: In function 'int main()':
luk.cpp:13:44: warning: unused variable 'cities' [-Wunused-variable]
     int n, a, b, start = 0, midpoint, end, cities; // n -> towns, a -> from, b -> to
                                            ^~~~~~
luk.cpp:14:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
luk.cpp:18:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d", &a, &b);
         ~~~~~^~~~~~~~~~~~~~~~~
#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...