Task: | Laskettelukeskus |
Sender: | Verlet |
Submission time: | 2023-11-03 13:49:00 +0200 |
Language: | C++ (C++17) |
Status: | COMPILE ERROR |
Compiler report
input/code.cpp:7:8: error: 'Node' was not declared in this scope 7 | vector<Node*> nodes; | ^~~~ input/code.cpp:7:13: error: template argument 1 is invalid 7 | vector<Node*> nodes; | ^ input/code.cpp:7:13: error: template argument 2 is invalid input/code.cpp: In function 'int main()': input/code.cpp:57:11: error: request for member 'push_back' in 'nodes', which is of non-class type 'int' 57 | nodes.push_back(&create_node(data[i])); | ^~~~~~~~~ input/code.cpp:57:33: error: taking address of rvalue [-fpermissive] 57 | nodes.push_back(&create_node(data[i])); | ~~~~~~~~~~~^~~~~~~~~ input/code.cpp:62:10: error: invalid types 'int[int]' for array subscript 62 | nodes[path_start[i]]->children.push_back(*nodes[path_end[i]]); | ^ input/code.cpp:62:52: error: invalid types 'int[int]' for array subscript 62 | nodes[path_start[i]]->children.push_back(*nodes[path_end[i]]);...
Code
#include <iostream> #include <vector> #include <deque> using namespace std; vector<Node*> nodes; struct Node { long data; vector<Node> children; }; Node create_node(long data) { Node node; node.data = data; node.children = vector<Node>(0); return node; } long eval(Node* root) { if (root->children.size() == 0) return root->data; long sum; for (Node child : root->children) { sum += eval(&child); } return max(root->data, sum); } int main() { int n; cin >> n; int path_start[n-1]; int path_end[n-1]; for (int i = 0; i < n - 1; i++) { cin >> path_start[i]; cin >> path_end[i]; } int data[n]; for (int i = 0; i < n; i++) { cin >> data[i]; } for (int i = 0; i < n; i++) { nodes.push_back(&create_node(data[i])); } for (int i = 0; i < n - 1; i++) { nodes[path_start[i]]->children.push_back(*nodes[path_end[i]]); } cout << eval(nodes[0]); }