Task: | Laskettelukeskus |
Sender: | Verlet |
Submission time: | 2023-10-30 17:28:02 +0200 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp: In function 'int haku(int)': input/code.cpp:10:7: error: 'v' was not declared in this scope 10 | if (v[i].size() == 0) return values[i]; | ^ input/code.cpp:10:9: error: 'i' was not declared in this scope 10 | if (v[i].size() == 0) return values[i]; | ^ input/code.cpp:10:32: error: 'values' was not declared in this scope 10 | if (v[i].size() == 0) return values[i]; | ^~~~~~ input/code.cpp:17:20: error: 'v' was not declared in this scope 17 | for (int child : v[i]) | ^ input/code.cpp:17:22: error: 'i' was not declared in this scope 17 | for (int child : v[i]) | ^ input/code.cpp:28:17: error: 'values' was not declared in this scope 28 | return max(s, values[index]); | ^~~~~~
Code
#include <iostream>#include <algorithm>#include <vector>using namespace std;int haku(int index){// If the node has no childrenif (v[i].size() == 0) return values[i];// The node has children// The number needed to plow the childrenint s = 0;for (int child : v[i]){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;vector<int> v[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);}