Task: | Laskettelukeskus |
Sender: | Verlet |
Submission time: | 2023-10-30 17:39:13 +0200 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int haku(int)': input/code.cpp:12:36: error: 'values' was not declared in this scope 12 | if (v[index].size() == 0) return values[index]; | ^~~~~~ input/code.cpp:30:17: error: 'values' was not declared in this scope 30 | return max(s, values[index]); | ^~~~~~ input/code.cpp: In function 'int main()': input/code.cpp:39:14: error: expected ';' before 'for' 39 | v.resize(n) | ^ | ; 40 | 41 | for (int i = 0; i < n; i++) | ~~~ input/code.cpp:41:19: error: 'i' was not declared in this scope 41 | for (int i = 0; i < n; i++) | ^
Code
#include <iostream>#include <algorithm>#include <vector>using namespace std;vector<vector<int>> v;int haku(int index){// If the node has no childrenif (v[index].size() == 0) return values[index];// The node has children// The number needed to plow the childrenint s = 0;for (int child : v[index]){s += haku(child);}/*Return the max of the number needed toplow the children and the number neededto plow the node*/return max(s, values[index]);}int main(){int n;cin >> n;v.resize(n)for (int i = 0; i < n; i++){int a, b;cin >> a >> b;v[a-1].push_back(b-1);}int values[n];for (int i = 0; i < n; i++){cin >> values[i];}cout << haku(0);}