Language: C++

#include <cstring>
#include <cstdlib>
using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

typedef vector<vector<int> > Graph;

vector<ll> A, ans;
Graph g;
vector<bool> visited ;
void dfs(const int cur, const ll sum) {
  //  cout << "DFS" << cur << "=" << sum << endl;                                                            
  visited[cur] = true;
  ans[cur] += sum;
  REP(i, g[cur].size()) {
    int nxt = g[cur][i];
    if(visited[nxt]) continue;
    dfs(nxt, ans[cur]);

  }
}

int main() {
  int N, Q; cin>>N>>Q;
  ans = vector<ll> (N, 0);
  g = Graph(N);
  visited = vector<bool>(N, false);
  REP(i,N-1) {
    int a, b; cin>>a>>b; a--; b--;
    g[a].push_back(b);
  }
  REP(i,Q) {
    int p, x;
    cin>>p>>x; p--;
    ans[p] += x;
  }
  //  pp(A, N);                                                                                              
  dfs(0,0);
  REP(i,N) {
    if(i > 0) cout << " ";
    cout << ans[i];
  }
  cout << endl;
  return 0;
}



Compiler output:
a.cc:7:9: error: 'pair' does not name a type
    7 | typedef pair<int, int> pint;
      |         ^~~~
a.cc: In function 'void pp(T, int)':
a.cc:10:51: error: 'cout' was not declared in this scope
   10 | template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }
      |                                                   ^~~~
a.cc:3:1: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
    2 | #include <cstdlib>
  +++ |+#include <iostream>
    3 | using namespace std;
a.cc:10:69: error: 'cout' was not declared in this scope
   10 | template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }
      |                                                                     ^~~~
a.cc:10:69: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:10:77: error: 'endl' was not declared in this scope
   10 | template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }
      |                                                                             ^~~~
a.cc:3:1: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
    2 | #include <cstdlib>
  +++ |+#include <ostream>
    3 | using namespace std;
a.cc: At global scope:
a.cc:12:33: error: 'string' does not name a type
   12 | void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
      |                                 ^~~~~~
a.cc:12:60: error: 'string' does not name a type
   12 | void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
      |                                                            ^~~~~~
a.cc: In function 'void TorF(bool, const int&, const int&)':
a.cc:13:3: error: 'cout' was not declared in this scope
   13 |   cout << (tf ? trueMessage : falseMessage) << endl;
      |   ^~~~
a.cc:13:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:13:48: error: 'endl' was not declared in this scope
   13 |   cout << (tf ? trueMessage : falseMessage) << endl;
      |                                                ^~~~
a.cc:13:48: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'
a.cc: In function 'void YESNO(bool)':
a.cc:15:39: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
   15 | void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
      |                                       ^~~~~
      |                                       |
      |                                       const char*
a.cc:12:41: note:   initializing argument 2 of 'void TorF(bool, const int&, const int&)'
   12 | void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
      |                           ~~~~~~~~~~~~~~^~~~~~~~~~~
a.cc:15:46: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
   15 | void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
      |                                              ^~~~
      |                                              |
      |                                              const char*
a.cc:12:68: note:   initializing argument 3 of 'void TorF(bool, const int&, const int&)'
   12 | void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
      |                                                      ~~~~~~~~~~~~~~^~~~~~~~~~~~
a.cc: In function 'void YesNo(bool)':
a.cc:16:39: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
   16 | void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
      |                                       ^~~~~
      |                                       |
      |                                       const char*
a.cc:12:41: note:   initializing argument 2 of 'void TorF(bool, const int&, const int&)'
   12 | void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
      |                           ~~~~~~~~~~~~~~^~~~~~~~~~~
a.cc:16:46: error: invalid conversion from 'const char*' to 'int' [-fpermissive]
   16 | void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }
      |                                              ^~~~
      |                                              |
      |                                              const char*
a.cc:12:68: note:   initializing argument 3 of 'void TorF(bool, const int&, const int&)'
   12 | void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
      |                                                      ~~~~~~~~~~~~~~^~~~~~~~~~~~
a.cc: At global scope:
a.cc:18:9: error: 'vector' does not name a type
   18 | typedef vector<vector<int> > Graph;
      |         ^~~~~~
a.cc:20:1: error: 'vector' does not name a type
   20 | vector<ll> A, ans;
      | ^~~~~~
a.cc:21:1: error: 'Graph' does not name a type
   21 | Graph g;
      | ^~~~~
a.cc:22:1: error: 'vector' does not name a type
   22 | vector<bool> visited ;
      | ^~~~~~
a.cc: In function 'void dfs(int, ll)':
a.cc:25:3: error: 'visited' was not declared in this scope
   25 |   visited[cur] = true;
      |   ^~~~~~~
a.cc:26:3: error: 'ans' was not declared in this scope; did you mean 'abs'?
   26 |   ans[cur] += sum;
      |   ^~~
      |   abs
a.cc:27:10: error: 'g' was not declared in this scope
   27 |   REP(i, g[cur].size()) {
      |          ^
a.cc:5:43: note: in definition of macro 'REP'
    5 | #define REP(i,n) for(int i = 0; i < (int)(n); i++)
      |                                           ^
a.cc: In function 'int main()':
a.cc:36:13: error: 'cin' was not declared in this scope
   36 |   int N, Q; cin>>N>>Q;
      |             ^~~
a.cc:36:13: note: 'std::cin' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:37:3: error: 'ans' was not declared in this scope; did you mean 'abs'?
   37 |   ans = vector<ll> (N, 0);
      |   ^~~
      |   abs
a.cc:37:9: error: 'vector' was not declared in this scope
   37 |   ans = vector<ll> (N, 0);
      |         ^~~~~~
a.cc:3:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
    2 | #include <cstdlib>
  +++ |+#include <vector>
    3 | using namespace std;
a.cc:37:18: error: expected primary-expression before '>' token
   37 |   ans = vector<ll> (N, 0);
      |                  ^
a.cc:38:3: error: 'g' was not declared in this scope
   38 |   g = Graph(N);
      |   ^
a.cc:38:7: error: 'Graph' was not declared in this scope
   38 |   g = Graph(N);
      |       ^~~~~
a.cc:39:3: error: 'visited' was not declared in this scope
   39 |   visited = vector<bool>(N, false);
      |   ^~~~~~~
a.cc:39:20: error: expected primary-expression before 'bool'
   39 |   visited = vector<bool>(N, false);
      |                    ^~~~
a.cc:52:15: error: 'cout' was not declared in this scope
   52 |     if(i > 0) cout << " ";
      |               ^~~~
a.cc:52:15: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:53:5: error: 'cout' was not declared in this scope
   53 |     cout << ans[i];
      |     ^~~~
a.cc:53:5: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:55:3: error: 'cout' was not declared in this scope
   55 |   cout << endl;
      |   ^~~~
a.cc:55:3: note: 'std::cout' is defined in header '<iostream>'; this is probably fixable by adding '#include <iostream>'
a.cc:55:11: error: 'endl' was not declared in this scope
   55 |   cout << endl;
      |           ^~~~
a.cc:55:11: note: 'std::endl' is defined in header '<ostream>'; this is probably fixable by adding '#include <ostream>'