Language: C++

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

int tot;
ll __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:1: error: 'll' does not name a type
   10 | ll __pow[M];
      | ^~
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 [200020][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)
      |             ^~~