Submission #88925

#TimeUsernameProblemLanguageResultExecution timeMemory
88925ahaaTriumphal arch (POI13_luk)C++14
Compilation error
0 ms0 KiB
#include <iostream> #include <vector> #include <algorithm> #include <unordered_set> #define avg(a, b) ((a + b) / 2) vector<vector<int>> treeOfCities; int numMoreWorkersNeeded(bool[] visited, int currWorkers, int currCity){ visited[currCity] = true; int numChildren = treeOfCities[currCity].size(); int childResSum = 0; int unBuildChildren = 0; for(int i = 0; i < numChildren; i++){ int currChild = treeOfCities[currCity][i]; if(!visited[currChild]){ unBuildChildren++; childResSum += numMoreWorkersNeeded(visited, currWorkers, currChild); } } if(currWorkers > unBuildChildren + childResSum){ return 0; }else { return unBuildChildren + childResSum - currWorkers; } } int main(){ int n; cin >> n; for(int i = 0; i < n; i++){ vector<int> v; treeOfCities.push_back(v); } int from; int to; for(int i = 0; i < n-1; i++){ cin >> from >> to; treeOfCities[from - 1].push_back(to - 1); treeOfCities[to - 1].push_back(from - 1); } int start = 0; int end = n; int result = 0; while(start < end){ int middle = avg(start, end); bool visited[n+10] = { false }; result = numMoreWorkersNeeded(visited, middle, 0); if(result != 0){ start = middle + 1; }else { end = middle; } } result = start; cout << result << endl; return 0; }

Compilation message (stderr)

luk.cpp:8:1: error: 'vector' does not name a type; did you mean 'perror'?
 vector<vector<int>> treeOfCities;
 ^~~~~~
 perror
luk.cpp:10:33: error: expected ',' or '...' before 'visited'
 int numMoreWorkersNeeded(bool[] visited, int currWorkers, int currCity){
                                 ^~~~~~~
luk.cpp: In function 'int numMoreWorkersNeeded(bool*)':
luk.cpp:11:5: error: 'visited' was not declared in this scope
     visited[currCity] = true;
     ^~~~~~~
luk.cpp:11:13: error: 'currCity' was not declared in this scope
     visited[currCity] = true;
             ^~~~~~~~
luk.cpp:12:23: error: 'treeOfCities' was not declared in this scope
     int numChildren = treeOfCities[currCity].size();
                       ^~~~~~~~~~~~
luk.cpp:19:58: error: 'currWorkers' was not declared in this scope
             childResSum += numMoreWorkersNeeded(visited, currWorkers, currChild);
                                                          ^~~~~~~~~~~
luk.cpp:22:8: error: 'currWorkers' was not declared in this scope
     if(currWorkers > unBuildChildren + childResSum){
        ^~~~~~~~~~~
luk.cpp: In function 'int main()':
luk.cpp:31:5: error: 'cin' was not declared in this scope
     cin >> n;
     ^~~
luk.cpp:31:5: note: suggested alternative:
In file included from luk.cpp:1:0:
/usr/include/c++/7/iostream:60:18: note:   'std::cin'
   extern istream cin;  /// Linked to standard input
                  ^~~
luk.cpp:33:9: error: 'vector' was not declared in this scope
         vector<int> v;
         ^~~~~~
luk.cpp:33:9: note: suggested alternative:
In file included from /usr/include/c++/7/vector:64:0,
                 from luk.cpp:2:
/usr/include/c++/7/bits/stl_vector.h:216:11: note:   'std::vector'
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
luk.cpp:33:16: error: expected primary-expression before 'int'
         vector<int> v;
                ^~~
luk.cpp:34:9: error: 'treeOfCities' was not declared in this scope
         treeOfCities.push_back(v);
         ^~~~~~~~~~~~
luk.cpp:34:32: error: 'v' was not declared in this scope
         treeOfCities.push_back(v);
                                ^
luk.cpp:41:3: error: 'treeOfCities' was not declared in this scope
   treeOfCities[from - 1].push_back(to - 1);
   ^~~~~~~~~~~~
luk.cpp:52:57: error: too many arguments to function 'int numMoreWorkersNeeded(bool*)'
         result = numMoreWorkersNeeded(visited, middle, 0);
                                                         ^
luk.cpp:10:5: note: declared here
 int numMoreWorkersNeeded(bool[] visited, int currWorkers, int currCity){
     ^~~~~~~~~~~~~~~~~~~~
luk.cpp:62:5: error: 'cout' was not declared in this scope
     cout << result << endl;
     ^~~~
luk.cpp:62:5: note: suggested alternative:
In file included from luk.cpp:1:0:
/usr/include/c++/7/iostream:61:18: note:   'std::cout'
   extern ostream cout;  /// Linked to standard output
                  ^~~~
luk.cpp:62:23: error: 'endl' was not declared in this scope
     cout << result << endl;
                       ^~~~
luk.cpp:62:23: note: suggested alternative:
In file included from /usr/include/c++/7/iostream:39:0,
                 from luk.cpp:1:
/usr/include/c++/7/ostream:590:5: note:   'std::endl'
     endl(basic_ostream<_CharT, _Traits>& __os)
     ^~~~