Language: C++

#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using PP = pair<int, long long>;

int N, Q, K;
vector<int> G[100000];
long long dist[100000];


long long calc(int l, int r) {
  return dist[l] + dist[r];
}

void dfs(int i, int prev) {
  for(PP p : G[i]) {
    int to = p.first;
    if(to == prev) continue;
    dist[to] = dist[i] + p.second;
    dfs(to, i);
  }
}

void solve() {
  fill(dist, dist + N, 1ll << 62);
  dist[K] = 0;
  dfs(K, -1);
}

int main() {
  cin >> N;
  for(int i = 0; i < N - 1; ++i) {
    int a,b,c;
    cin >> a >> b >> c;
    --a; --b;
    G[a].push_back(PP(b, c));
    G[b].push_back(PP(a, c));
  }
  
  cin >> Q >> K;
  --K;
  solve();
  for(int i = 0; i < Q; ++i) {
    int l, r;
    cin >> l >> r;
    --l; --r;
    cout << calc(l, r) << endl;  
  }
  return 0;
}

Compiler output:
a.cc:5:12: error: 'pair' does not name a type
    5 | using PP = pair<int, long long>;
      |            ^~~~
a.cc:8:1: error: 'vector' does not name a type
    8 | vector<int> G[100000];
      | ^~~~~~
a.cc: In function 'void dfs(int, int)':
a.cc:17:7: error: 'PP' was not declared in this scope
   17 |   for(PP p : G[i]) {
      |       ^~
a.cc:23:1: error: expected primary-expression before '}' token
   23 | }
      | ^
a.cc:22:4: error: expected ';' before '}' token
   22 |   }
      |    ^
      |    ;
   23 | }
      | ~   
a.cc:23:1: error: expected primary-expression before '}' token
   23 | }
      | ^
a.cc:22:4: error: expected ')' before '}' token
   22 |   }
      |    ^
      |    )
   23 | }
      | ~   
a.cc:17:6: note: to match this '('
   17 |   for(PP p : G[i]) {
      |      ^
a.cc:23:1: error: expected primary-expression before '}' token
   23 | }
      | ^
a.cc: In function 'void solve()':
a.cc:26:3: error: 'fill' was not declared in this scope; did you mean 'std::fill'?
   26 |   fill(dist, dist + N, 1ll << 62);
      |   ^~~~
      |   std::fill
In file included from /usr/include/c++/14/algorithm:86,
                 from a.cc:4:
/usr/include/c++/14/pstl/glue_algorithm_defs.h:191:1: note: 'std::fill' declared here
  191 | fill(_ExecutionPolicy&& __exec, _ForwardIterator __first, _ForwardIterator __last, const _Tp& __value);
      | ^~~~
a.cc: In function 'int main()':
a.cc:32:3: error: 'cin' was not declared in this scope; did you mean 'std::cin'?
   32 |   cin >> N;
      |   ^~~
      |   std::cin
In file included from a.cc:1:
/usr/include/c++/14/iostream:62:18: note: 'std::cin' declared here
   62 |   extern istream cin;           ///< Linked to standard input
      |                  ^~~
a.cc:37:5: error: 'G' was not declared in this scope
   37 |     G[a].push_back(PP(b, c));
      |     ^
a.cc:37:20: error: 'PP' was not declared in this scope
   37 |     G[a].push_back(PP(b, c));
      |                    ^~
a.cc:48:5: error: 'cout' was not declared in this scope; did you mean 'std::cout'?
   48 |     cout << calc(l, r) << endl;
      |     ^~~~
      |     std::cout
/usr/include/c++/14/iostream:63:18: note: 'std::cout' declared here
   63 |   extern ostream cout;          ///< Linked to standard output
      |                  ^~~~
a.cc:48:27: error: 'endl' was not declared in this scope; did you mean 'std::endl'?
   48 |     cout << calc(l, r) << endl;
      |                           ^~~~
      |                           std::endl
In file included from /usr/include/c++/14/iostream:41:
/usr/include/c++/14/ostream:744:5: note: 'std::endl' declared here
  744 |     endl(basic_ostream<_CharT, _Traits>& __os)
      |     ^~~~