Language: C++

//==========================================
// ABC138d
//
// 2019/08/18
//==========================================

#include <iostream>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>

using namespace std;

int main(int argc, char* argv[])
{
  int n, q;
  cin >> n >> q;
  vector<vector<int>> a(n+1);
  a.assign(n+1, vector<int>(n+1));
  

  for(int i=1; i<n; i++)
  {
    int t1, t2;
    cin >> t1 >> t2;
    a[t1][0]=t1;
    a[t2][0]=t2;
    for(int j=1; j<n+1; j++)
    {
      auto it=find(a[j].begin(), a[j].end(), t1);
      if(it != a[j].end())
      {
        a[j].push_back(t2);
      }
    }
  }

  vector<long> cnt(n+1);
  for(int i=0; i<q; i++)
  {
    int p, x;
    cin >> p >> x;    
    for(auto j=a[p].begin(), j!=a[p].end(); ++J)
    {
      cnt[a[p]][j] += x;
    }
  }

  for(int i=1; i<n+1; i++)
  {
    cout << cnt[i] << " " << flush;
  }
  cout << endl;

/*
  vector<vector<int>> a(n);
  for(int i=0; i<n; i++)
  {
    int t1, t2;
    cin >> t1 >> t2;
    a[t1].push_back(t2);
    for(auto j=a)
  }

*/

//  vector<long> cnt;


  return 0;
}

Compiler output:
a.cc: In function 'int main(int, char**)':
a.cc:46:31: error: expected ';' before '!=' token
   46 |     for(auto j=a[p].begin(), j!=a[p].end(); ++J)
      |                               ^~
      |                               ;
a.cc:46:31: error: expected primary-expression before '!=' token
   46 |     for(auto j=a[p].begin(), j!=a[p].end(); ++J)
      |                               ^~
a.cc:46:47: error: 'J' was not declared in this scope
   46 |     for(auto j=a[p].begin(), j!=a[p].end(); ++J)
      |                                               ^
a.cc:48:10: error: no match for 'operator[]' (operand types are 'std::vector<long int>' and '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'})
   48 |       cnt[a[p]][j] += x;
      |          ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:10:
/usr/include/c++/14/bits/stl_vector.h:1128:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](size_type) [with _Tp = long int; _Alloc = std::allocator<long int>; reference = long int&; size_type = long unsigned int]'
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1128:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1128 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_vector.h:1147:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](size_type) const [with _Tp = long int; _Alloc = std::allocator<long int>; const_reference = const long int&; size_type = long unsigned int]'
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:1147:28: note:   no known conversion for argument 1 from '__gnu_cxx::__alloc_traits<std::allocator<std::vector<int> >, std::vector<int> >::value_type' {aka 'std::vector<int>'} to 'std::vector<long int>::size_type' {aka 'long unsigned int'}
 1147 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~