Language: C++

#include <iostream>
#include <cstdio>
#define ll long long
const int maxn=100000*2+100;
ll n,m,i,xx[maxn],yy[maxn],to[maxn],root,x,y,last[maxn],next[maxn],next1[maxn],last1[maxn],to1[maxn],ans[maxn],fa[maxn],v[maxn],z,dis[maxn],from[maxn];
using namespace std;
inline void read(ll &k)
{
    ll f=1;char c=getchar();k=0;
    while (c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
    while (c>='0'&&c<='9')k=k*10+c-'0',c=getchar();
    k*=f;
}
inline ll gf(ll now)
{
    return fa[now]==now?now:fa[now]=gf(fa[now]);
}
void dfs(ll now)
{
    v[now]=1;
    for(ll cur=last[now];cur;cur=next[cur])
    {
        if (!v[to[cur]])
        {
        	from[to[cur]]=from[now]+dis[cur];
            dfs(to[cur]);
            fa[to[cur]]=now;
        }
    }
    for (ll cur=last1[now];cur;cur=next1[cur])
    if (v[to1[cur]])ans[(cur+1)>>1]=gf(to1[cur]);
}
int main()
{
    read(n);
    for (i=1;i<n;i++)
    {
        read(x);read(y);read(z);
        to[i*2-1]=y;
        dis[i*2-1]=z;
        next[i*2-1]=last[x];
        last[x]=i*2-1;
        to[i*2]=x;
        dis[i*2]=z;
        next[i*2]=last[y];
        last[y]=i*2;
    }
    read(m);read(root);
    for (i=1;i<=m;i++)
    {
        read(x);read(y);
        xx[i]=x;yy[i]=y;
        to1[i*2-1]=y;
        next1[i*2-1]=last1[x];
        last1[x]=i*2-1;
        to1[i*2]=x;
        next1[i*2]=last1[y];
        last1[y]=i*2;
    }
    for (i=1;i<=n;i++)fa[i]=i;
    dfs(root);
    for (i=1;i<=m;i++)
    printf("%lld\n",from[xx[i]]+from[yy[i]]);
}

Compiler output:
a.cc: In function 'void dfs(long long int)':
a.cc:21:34: error: reference to 'next' is ambiguous
   21 |     for(ll cur=last[now];cur;cur=next[cur])
      |                                  ^~~~
In file included from /usr/include/c++/14/string:47,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:5:57: note:                 'long long int next [200100]'
    5 | ll n,m,i,xx[maxn],yy[maxn],to[maxn],root,x,y,last[maxn],next[maxn],next1[maxn],last1[maxn],to1[maxn],ans[maxn],fa[maxn],v[maxn],z,dis[maxn],from[maxn];
      |                                                         ^~~~
a.cc: In function 'int main()':
a.cc:41:9: error: reference to 'next' is ambiguous
   41 |         next[i*2-1]=last[x];
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:5:57: note:                 'long long int next [200100]'
    5 | ll n,m,i,xx[maxn],yy[maxn],to[maxn],root,x,y,last[maxn],next[maxn],next1[maxn],last1[maxn],to1[maxn],ans[maxn],fa[maxn],v[maxn],z,dis[maxn],from[maxn];
      |                                                         ^~~~
a.cc:45:9: error: reference to 'next' is ambiguous
   45 |         next[i*2]=last[y];
      |         ^~~~
/usr/include/c++/14/bits/stl_iterator_base_funcs.h:232:5: note: candidates are: 'template<class _InputIterator> constexpr _InputIterator std::next(_InputIterator, typename iterator_traits<_Iter>::difference_type)'
  232 |     next(_InputIterator __x, typename
      |     ^~~~
a.cc:5:57: note:                 'long long int next [200100]'
    5 | ll n,m,i,xx[maxn],yy[maxn],to[maxn],root,x,y,last[maxn],next[maxn],next1[maxn],last1[maxn],to1[maxn],ans[maxn],fa[maxn],v[maxn],z,dis[maxn],from[maxn];
      |                                                         ^~~~