Language: C++

#include<cstdio>
#include<cstring>
#include<iostream>
#define lowbit(x) ((x)&(-x))
using namespace std;
typedef unsigned long long ull;
const int N=2e3+100,maxn=31;
struct edge{
	int x,y,next;
}a[2*N];int len,last[N];
ull g[N][35],d[70];
void ins(int x,int y){
	a[++len].x=x;a[len].y=y;
	a[len].next=last[x];last[x]=len;
}
ull h[N][35];
bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
void dfs(int x){
	bk[x]=false;dfn[x]=++tot;
	h[dfn[x]][(dfn[x]-1)/64]^=d[(dfn[x]-1)%64];
	size[dfn[x]]++;
	for(int k=last[x];k;k=a[k].next){
		int y=a[k].y;
		if(bk[y]){
			for(int i=0;i<=maxn;i++) h[dfn[y]][i]=h[dfn[x]][i];
			dfs(y);
			for(int i=dfn[x];i<dfn[x]+size[dfn[x]];i++)
				for(int j=dfn[y];j<dfn[y]+size[dfn[y]];j++)
					LCA[i][j]=LCA[j][i]=dfn[x];
			for(int j=dfn[y];j<dfn[y]+size[dfn[y]];j++)
				LC[dfn[x]][j]=dfn[y];
			fa[dfn[y]]=dfn[x];
			size[dfn[x]]+=size[dfn[y]];
		}
	}
}
int list[N*N][2],sum=0,Son[N][35],ID[110];

int main()
{
	int n,m;scanf("%d%d",&n,&m);
	len=0;memset(last,0,sizeof(last));
	for(int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		ins(x,y);ins(y,x);
	}
	d[0]=1;for(int i=1;i<=63;i++) d[i]=d[i-1]*2;
	for(int i=0;i<=63;i++) ID[d[i]%101]=i;
	memset(bk,true,sizeof(bk));
	dfs(1);
	ull Maxn=0;for(int i=0;i<=63;i++) Maxn^=d[i];
	for(int i=1;i<=n;i++)
		for(int j=i;j<size[i]+i;j++)
			Son[i][(j-1)/64]^=d[(j-1)%64];
	while(m--){
		int x,y;
		scanf("%d%d",&x,&y);
		x=dfn[x];y=dfn[y];
		g[x][(y-1)/64]^=d[(y-1)%64];
		g[y][(x-1)/64]^=d[(x-1)%64];
		list[++sum][0]=x;list[sum][1]=y;
	}
	int id=1;
	while(id<=sum){
		int x=list[id][0],y=list[id][1];
		if(x>y) swap(x,y);
		for(int i=0;i<=maxn;i++){
			ull t;
			if(x+size[x]>y) t=((Son[y][i]|(Maxn-Son[LC[x][y]][i])|(h[y][i]-h[fa[x]][i]))&((g[x][i]&(Maxn-g[y][i]))|(g[y][i]&(Maxn-g[x][i]))));
			else t=((Son[y][i]|Son[x][i]|(h[x][i]-h[fa[LCA[x][y]]][i])|(h[y][i]-h[fa[LCA[x][y]]][i]))&((g[x][i]&(Maxn-g[y][i]))|(g[y][i]&(Maxn-g[x][i]))));
			while(t){
				ull t2=lowbit(t);
				int t3=i*64+ID[t2%101]+1;
				if((g[y][i]&t2)==0){
					g[y][i]|=t2;list[++sum][0]=y;list[sum][1]=t3;
					g[t3][(y-1)/64]|=d[(y-1)%64];
				}
				if((g[x][i]&t2)==0){
					g[x][i]|=t2;list[++sum][0]=x;list[sum][1]=t3;
					g[t3][(x-1)/64]|=d[(x-1)%64];
				}
				t^=t2;
			}
		}
		id++;
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			if((g[i][(j-1)/64]&d[(j-1)%64])) ans++;
	printf("%d\n",ans);
	return 0;
}

Compiler output:
a.cc: In function 'void dfs(int)':
a.cc:21:9: error: reference to 'size' is ambiguous
   21 |         size[dfn[x]]++;
      |         ^~~~
In file included from /usr/include/c++/14/string:53,
                 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:3:
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc:27:51: error: reference to 'size' is ambiguous
   27 |                         for(int i=dfn[x];i<dfn[x]+size[dfn[x]];i++)
      |                                                   ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc:28:59: error: reference to 'size' is ambiguous
   28 |                                 for(int j=dfn[y];j<dfn[y]+size[dfn[y]];j++)
      |                                                           ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc:30:51: error: reference to 'size' is ambiguous
   30 |                         for(int j=dfn[y];j<dfn[y]+size[dfn[y]];j++)
      |                                                   ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc:33:25: error: reference to 'size' is ambiguous
   33 |                         size[dfn[x]]+=size[dfn[y]];
      |                         ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc:33:39: error: reference to 'size' is ambiguous
   33 |                         size[dfn[x]]+=size[dfn[y]];
      |                                       ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc: In function 'int main()':
a.cc:54:31: error: reference to 'size' is ambiguous
   54 |                 for(int j=i;j<size[i]+i;j++)
      |                               ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~
a.cc:70:30: error: reference to 'size' is ambiguous
   70 |                         if(x+size[x]>y) t=((Son[y][i]|(Maxn-Son[LC[x][y]][i])|(h[y][i]-h[fa[x]][i]))&((g[x][i]&(Maxn-g[y][i]))|(g[y][i]&(Maxn-g[x][i]))));
      |                              ^~~~
/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:17:43: note:                 'int size [2100]'
   17 | bool pd=true,bk[N];int fa[N],tot=0,dfn[N],size[N],LCA[N][N],LC[N][N];
      |                                           ^~~~