Language: C++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
#define N 200010
#define M 25

int tot;
int __pow[M];
int head[N];
struct edge{
    int u,v,w,next;
}e[2*N];
int ver[2*N],R[2*N],first[N];long long dir[N];
int dp[2*N][30];
bool vis[N];

inline void add(int u , int v ,int w ,int &k)
{
    e[k].u = u; e[k].v = v; e[k].w = w;
    e[k].next = head[u]; head[u] = k++;
    u = u^v; v = u^v; u = u^v;
    e[k].u = u; e[k].v = v; e[k].w = w;
    e[k].next = head[u]; head[u] = k++;
}

void dfs(int u ,int dep)
{
    vis[u] = true; first[u] = ++tot; ver[tot] = u; R[tot] = dep;
    for(int k=head[u]; k!=-1; k=e[k].next)
        if( !vis[e[k].v] )
        {
            int v = e[k].v , w = e[k].w;
            dir[v] = dir[u] + w;
            dfs(v,dep+1);
            ver[++tot] = u; R[tot] = dep;
        }
}
void ST(int len)
{
    int K = (int)(log((double)(len)) / log(2.0));
    for(int i=1; i<=len; i++) dp[i][0] = i;
    for(int j=1; j<=K; j++)
        for(int i=1; i+__pow[j]-1 <= len; i++)
        {
            int a = dp[i][j-1] , b = dp[i+__pow[j-1]][j-1];
            if(R[a] < R[b]) dp[i][j] = a;
            else            dp[i][j] = b;
        }
}

int RMQ(int x ,int y)
{
    int K = (int)(log((double)(y-x+1)) / log(2.0));
    int a = dp[x][K] , b = dp[y-__pow[K]+1][K];
    if(R[a] < R[b]) return a;
    else            return b;
}

int LCA(int u ,int v)
{
    int x = first[u] , y = first[v];
    if(x > y) swap(x,y);
    int index = RMQ(x,y);
    return ver[index];
}

int main()
{
    for(int i=0; i<M; i++) __pow[i] = (1<<i);
    int n,m,k;
    scanf("%d",&n);
        k = 0;
        memset(head,-1,sizeof(head));
        memset(vis,false,sizeof(vis));
        for(int i=1;i<n;i++)
        {
            int u,v,w;
            scanf("%d%d%d",&u,&v,&w);
            add(u,v,w);
        }
        int q,kk;
        scanf("%d%d",&q,&kk);
        tot = dir[k] = 0;
        dfs(kk,1);
        ST(tot);
        while(q--)
        {
            int u,v,lca;
            scanf("%d%d",&u,&v);
            lca = LCA(u,v);
            if(lca==k)
                printf("%lld\n",dir[u] + dir[v] - 2*dir[lca]);
            else
            {
                printf("%lld\n",dir[u] + dir[v]);
            }
        }
    return 0;
}


Compiler output:
a.cc:10:12: error: 'int __pow [25]' redeclared as different kind of entity
   10 | int __pow[M];
      |            ^
In file included from /usr/include/features.h:523,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/os_defines.h:39,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/c++config.h:683,
                 from /usr/include/c++/14/bits/requires_hosted.h:31,
                 from /usr/include/c++/14/iostream:38,
                 from a.cc:1:
/usr/include/x86_64-linux-gnu/bits/mathcalls.h:173:1: note: previous declaration 'double __pow(double, double)'
  173 | __MATHCALL_VEC (pow,, (_Mdouble_ __x, _Mdouble_ __y));
      | ^~~~~~~~~~~~~~
a.cc: In function 'void ST(int)':
a.cc:45:31: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   45 |         for(int i=1; i+__pow[j]-1 <= len; i++)
      |                               ^
a.cc:45:23: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   45 |         for(int i=1; i+__pow[j]-1 <= len; i++)
      |                      ~^~~~~~~~~
a.cc:45:32: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   45 |         for(int i=1; i+__pow[j]-1 <= len; i++)
      |                      ~~~~~~~~~~^~
a.cc:45:35: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
   45 |         for(int i=1; i+__pow[j]-1 <= len; i++)
      |                      ~~~~~~~~~~~~~^~~~~~
a.cc:47:52: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   47 |             int a = dp[i][j-1] , b = dp[i+__pow[j-1]][j-1];
      |                                                    ^
cc1plus: warning: pointer to a function used in arithmetic [-Wpointer-arith]
a.cc:47:42: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   47 |             int a = dp[i][j-1] , b = dp[i+__pow[j-1]][j-1];
      |                                         ~^~~~~~~~~~~
a.cc:47:40: error: invalid types 'int [400020][30][double (*)(double, double) noexcept]' for array subscript
   47 |             int a = dp[i][j-1] , b = dp[i+__pow[j-1]][j-1];
      |                                        ^
a.cc: In function 'int RMQ(int, int)':
a.cc:56:40: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   56 |     int a = dp[x][K] , b = dp[y-__pow[K]+1][K];
      |                                        ^
a.cc:56:32: error: invalid operands of types 'int' and 'double(double, double) noexcept' to binary 'operator-'
   56 |     int a = dp[x][K] , b = dp[y-__pow[K]+1][K];
      |                               ~^~~~~~~~~
      |                               |        |
      |                               int      double(double, double) noexcept
a.cc: In function 'int main()':
a.cc:71:35: warning: pointer to a function used in arithmetic [-Wpointer-arith]
   71 |     for(int i=0; i<M; i++) __pow[i] = (1<<i);
      |                                   ^
a.cc:71:37: error: assignment of read-only location '*(__pow + ((sizetype)i))'
   71 |     for(int i=0; i<M; i++) __pow[i] = (1<<i);
      |                            ~~~~~~~~~^~~~~~~~
a.cc:81:16: error: too few arguments to function 'void add(int, int, int, int&)'
   81 |             add(u,v,w);
      |             ~~~^~~~~~~
a.cc:19:13: note: declared here
   19 | inline void add(int u , int v ,int w ,int &k)
      |             ^~~