Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 9999999999;
template<class T> inline bool chmin(T& a, T b){if (a>b){a = b; return true;}return false;}
template<class T> inline bool chmax(T& a, T b){if (a<b){a = b; return true;}return false;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
  T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }

int N,Q,K;
vector<vector<pair<int,int>>> G; // グラフ
vector<ll> Dis; // 頂点Kからの距離
vector<bool> seen;

void dfs(int v){
  seen.at(v) = true;
  for (auto p : G.at(v)){
    auto nv = p.first;
    auto distance = p.second;
    if (seen.at(nv)) continue; // 既に訪れていればスキップ
    Dis.at(nv) = Dis.at(v) + distance;
    dfs(nv);
  }
}

int main() {
  cin >>N;
  G.assign(N, vector<int>());
  rep(i,N-1){
    int a,b,c; cin >>a >>b >>c;
    a--; b--;
    G.at(a).push_back(make_pair(b,c));
    G.at(b).push_back(make_pair(a,c));
  }
  cin >>Q >>K;

  seen.assign(N, false);
  Dis.assign(N, -1);
  K--;
  Dis.at(K) = 0;
  dfs(K);

  rep(i, Q){
    int a,b; cin >>a >>b;
    a--; b--;
    cout <<Dis.at(a) + Dis.at(b) <<endl;
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:32:11: error: no matching function for call to 'std::vector<std::vector<std::pair<int, int> > >::assign(int&, std::vector<int>)'
   32 |   G.assign(N, vector<int>());
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_vector.h:828:9: note: candidate: 'template<class _InputIterator, class> void std::vector<_Tp, _Alloc>::assign(_InputIterator, _InputIterator) [with <template-parameter-2-2> = _InputIterator; _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  828 |         assign(_InputIterator __first, _InputIterator __last)
      |         ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:828:9: note:   template argument deduction/substitution failed:
a.cc:32:11: note:   deduced conflicting types for parameter '_InputIterator' ('int' and 'std::vector<int>')
   32 |   G.assign(N, vector<int>());
      |   ~~~~~~~~^~~~~~~~~~~~~~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(size_type, const value_type&) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >; size_type = long unsigned int; value_type = std::vector<std::pair<int, int> >]'
  808 |       assign(size_type __n, const value_type& __val)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:808:47: note:   no known conversion for argument 2 from 'std::vector<int>' to 'const std::vector<std::vector<std::pair<int, int> > >::value_type&' {aka 'const std::vector<std::pair<int, int> >&'}
  808 |       assign(size_type __n, const value_type& __val)
      |                             ~~~~~~~~~~~~~~~~~~^~~~~
/usr/include/c++/14/bits/stl_vector.h:855:7: note: candidate: 'void std::vector<_Tp, _Alloc>::assign(std::initializer_list<_Tp>) [with _Tp = std::vector<std::pair<int, int> >; _Alloc = std::allocator<std::vector<std::pair<int, int> > >]'
  855 |       assign(initializer_list<value_type> __l)
      |       ^~~~~~
/usr/include/c++/14/bits/stl_vector.h:855:7: note:   candidate expects 1 argument, 2 provided