Language: C++

#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+5,maxm=2e5+5;
long long d[maxn];
int head[maxn];
int size=0;
struct edge
{
	int to,next;
	long long val;
}e[maxn];
void addedge(int u,int v,long long w)
{
	e[++size].to=v;
	e[size].val=w;
	e[size].next=head[u];
	head[u]=size;
}
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch>'9'||ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch<='9'&&ch>='0'){x=(x<<3)+(x<<1)+ch-'0';ch=getchar();}
	return x*f;
}
void dfs(int u,int fa)
{
	for(int i=head[u];i;i=e[i].next)
	{
		int to=e[i].to;
		if(to==fa)continue;
		d[to]=d[u]+e[i].val;
		dfs(to,u);
	}
}
int main()
{
	int n=read();
	for(int i=1;i<n;i++)
	{
		int u=read(),v=read()
		long long w=read();
		addedge(u,v,w);
		addedge(v,u,w);	
	}
	int q=read(),k=read();
	dfs(k,0);
	for(int i=1;i<=q;i++)
	{
		int x=read(),y=read();
		printf("%lld\n",d[x]+d[y]);
	}
	return 0;
}

Compiler output:
a.cc: In function 'void addedge(int, int, long long int)':
a.cc:14:13: error: reference to 'size' is ambiguous
   14 |         e[++size].to=v;
      |             ^~~~
In file included from /usr/include/c++/14/string:53,
                 from /usr/include/c++/14/bitset:52,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:52,
                 from a.cc:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:5: note:                 'int size'
    6 | int size=0;
      |     ^~~~
a.cc:15:11: error: reference to 'size' is ambiguous
   15 |         e[size].val=w;
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:5: note:                 'int size'
    6 | int size=0;
      |     ^~~~
a.cc:16:11: error: reference to 'size' is ambiguous
   16 |         e[size].next=head[u];
      |           ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:5: note:                 'int size'
    6 | int size=0;
      |     ^~~~
a.cc:17:17: error: reference to 'size' is ambiguous
   17 |         head[u]=size;
      |                 ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:6:5: note:                 'int size'
    6 | int size=0;
      |     ^~~~
a.cc: In function 'int main()':
a.cc:42:17: error: expected ',' or ';' before 'long'
   42 |                 long long w=read();
      |                 ^~~~
a.cc:43:29: error: 'w' was not declared in this scope
   43 |                 addedge(u,v,w);
      |                             ^