CSES - Datatähti 2024 alku - Results
Submission details
Task:Laskettelukeskus
Sender:Verlet
Submission time:2023-10-30 18:05:11 +0200
Language:C++ (C++17)
Status:COMPILE ERROR

Compiler report

input/code.cpp: In function 'int haku(int)':
input/code.cpp:20:40: error: invalid use of member function 'std::vector<_Tp, _Alloc>::size_type std::vector<_Tp, _Alloc>::size() const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::size_type = long unsigned int]' (did you forget the '()' ?)
   20 |   for (int child = 0; child < v[index].size)
      |                                            ()
input/code.cpp:20:44: error: expected ';' before ')' token
   20 |   for (int child = 0; child < v[index].size)
      |                                            ^
      |                                            ;

Code

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

vector<vector<int>> v;
vector<int> values;

int haku(int index)
{
  // If the node has no children
  if (v[index].size() == 0) return values[index];

  // The node has children
  
  // The number needed to plow the children
  int s = 0;

  for (int child = 0; child < v[index].size)
  {
    s += haku(v[index][child]);
  }

  /*
  Return the max of the number needed to
  plow the children and the number needed
  to plow the node
  */

  return max(s, values[index]);
}

int main()
{
  int n = 10;

  cin >> n;

  v.resize(n);
  values.resize(n);

  for (int i = 0; i < n; i++)
  {
    int a, b;

    cin >> a >> b;

    v[a-1].push_back(b-1);
  }

  for (int i = 0; i < n; i++)
  {
    cin >> values[i];
  }

  cout << haku(0);
}