Language: C++

//# define FLAG
///delet....................................
# include <iostream>
# include <cstring>
# include <cstdlib>
# include <cstdio>
# include <string>
# include <cmath>
# include <ctime>
# include <set>
# include <map>
# include <queue>
# include <stack>
# include <bitset>
# include <vector>
# include <fstream>
# include <algorithm>
using namespace std;
# define eps 1e-8
# define pb push_back
# define mp make_pair
# define pi acos(-1.0)
# define bug puts("H");
# define mem(a,b) memset(a,b,sizeof(a))
# define IOS ios::sync_with_stdio(false);
# define FO(i,n,a) for(int i=n; i>=a; --i)
# define FOR(i,a,n) for(int i=a; i<=n; ++i)
# define INF 0x3f3f3f3f
# define MOD 1000000007
///           123456789
//# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef unsigned long long ULL;
typedef long long LL;
inline int Scan(){
    int x=0,f=1; char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-') f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
///coding...................................

const int MAXM=100005;
LL d[MAXM],n;
LL ans=1000000000000000;
vector<pair<int,int> >G;

void dfs(int x, int fa){
    for (int i=0; i<G[x].size(); ++i) {
        int v=G[x][i].first, w=G[x][i].second;
        if (v==fa) continue;
        d[v]=d[x]+w;
        dfs(v,x);
    }
}

int main()
{
    IOS;
#ifdef FLAG
    freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
#endif /// FLAG
    cin>>n;
    int x, y, step;
    FOR(i,1,n-1)cin>>x>>y>>step, G[x].pb(mp(y,step)), G[y].pb(mp(x,step));
    int q,k,x1,y1;
    cin>>q>>k;
    dfs(k,0);
    while(q--) {
        cin>>x1>>y1;
        cout<<d[x1]+d[y1]<<endl;
    }
    return 0;
}


Compiler output:
a.cc: In function 'void dfs(int, int)':
a.cc:48:26: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'size'
   48 |     for (int i=0; i<G[x].size(); ++i) {
      |                          ^~~~
a.cc:49:19: error: no match for 'operator[]' (operand types are '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'std::pair<int, int>'} and 'int')
   49 |         int v=G[x][i].first, w=G[x][i].second;
      |                   ^
a.cc:51:19: error: 'w' was not declared in this scope
   51 |         d[v]=d[x]+w;
      |                   ^
a.cc: In function 'int main()':
a.cc:20:13: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'push_back'
   20 | # define pb push_back
      |             ^~~~~~~~~
a.cc:65:39: note: in expansion of macro 'pb'
   65 |     FOR(i,1,n-1)cin>>x>>y>>step, G[x].pb(mp(y,step)), G[y].pb(mp(x,step));
      |                                       ^~
a.cc:20:13: error: '__gnu_cxx::__alloc_traits<std::allocator<std::pair<int, int> >, std::pair<int, int> >::value_type' {aka 'struct std::pair<int, int>'} has no member named 'push_back'
   20 | # define pb push_back
      |             ^~~~~~~~~
a.cc:65:60: note: in expansion of macro 'pb'
   65 |     FOR(i,1,n-1)cin>>x>>y>>step, G[x].pb(mp(y,step)), G[y].pb(mp(x,step));
      |                                                            ^~