Language: C++

#include<bits/stdc++.h>
using namespace std;
const int inf=0x3f3f3f3f;
	int T;
	int n;
	struct data{
    int to,nxt;
};
	struct Graph{
    int ma[55][55];
    int d[55];
    int ed[55][2];
    int oe[55];
    data mp[110];
    int head[55],cnt;
    void clear()
    {
        memset(ma,0,sizeof(ma));
        memset(d,0,sizeof(d));
        memset(ed,0,sizeof(ed));
        memset(oe,0,sizeof(oe));
        memset(head,0,sizeof(head));cnt=0;
    }
    void ins()
    {
        int xx,yy;
        for(int i=1;i<n;++i)
        {
            scanf("%d%d",&xx,&yy);
            ed[i][0]=xx;ed[i][1]=yy;
            d[xx]++;d[yy]++;
            oe[xx]=oe[yy]=i;
            ma[xx][yy]=ma[yy][xx]=1;
        }
    }
    void link(int x,int y)
    {
        mp[++cnt].to=y;
        mp[cnt].nxt=head[x];
        head[x]=cnt;
    }
    int fa[55];
    void dfs(int x,int f)
    {
        fa[x]=f;
        for(int i=head[x];i;i=mp[i].nxt)
            if(mp[i].to!=f)
                dfs(mp[i].to,x);
    }
}A,B;
void build_B()
{
    for(int i=1;i<n;++i)
    {
        B.link(B.ed[i][0],B.ed[i][1]);
        B.link(B.ed[i][1],B.ed[i][0]);
    }
}
	int ch[55];
	data mp[110];
	int head[55],cnt;
	int d[55];
	bool in[55];
void link(int x,int y)
{
    mp[++cnt].to=y;
    mp[cnt].nxt=head[x];
    head[x]=cnt;
    in[x]=in[y]=1;
}
	bool ot[55];
	bool Topsort()
{
    queue<int>q;
    memset(ot,0,sizeof(ot));
    for(int i=1;i<=n;++i)
        if(in[i]&&!d[i])
            ot[i]=1,q.push(i);
    int u,v;
    while(!q.empty())
    {
        u=q.front();q.pop();
        for(int i=head[u];i;i=mp[i].nxt)
        {
            v=mp[i].to;
            d[v]--;
            if(!d[v])ot[v]=1,q.push(v);
        }
    }
    for(int i=1;i<=n;++i)
        if(in[i]&&!ot[i])return 0;
    return 1;
}
	int solve(int rt,int ano,int id)
{
    memset(A.head,0,sizeof(A.head));
    A.cnt=0;
    for(int i=1;i<n;++i)
    {
        if(i==id)continue;
        A.link(A.ed[i][0],A.ed[i][1]);
        A.link(A.ed[i][1],A.ed[i][0]);
    }
    A.link(rt,ano);A.link(ano,rt);
    A.dfs(rt,0);B.dfs(rt,0);
    int res=0;
    for(int i=1;i<=n;++i) ch[i]=(A.fa[i]!=B.fa[i]),res+=ch[i];
    memset(head,0,sizeof(head));cnt=0;
    memset(d,0,sizeof(d));
    memset(in,0,sizeof(in));
    for(int i=1;i<=n;++i)
    {
        if(i==rt)continue;
        if(!ch[i]&&ch[A.fa[i]])return inf;
        if(ch[i]&&ch[A.fa[i]]) link(i,A.fa[i]),d[A.fa[i]]++;
        if(ch[i]&&ch[B.fa[i]]) link(B.fa[i],i),d[i]++;
    }
    if(Topsort())return res;
    else return inf;
}
int main()
{
    scanf("%d",&T);
    while(T--)
    {
        scanf("%d",&n);
        A.clear();B.clear();
        A.ins();  B.ins();
        build_B();
        int ans=inf;
        for(int rt=1;rt<=n;++rt)
        {
            if(A.d[rt]!=1)continue;
            for(int f=1;f<=n;++f)
            {
                if(f==rt)continue;
                ans=min(ans,(A.ma[rt][f]^1)+solve(rt,f,A.oe[rt]));
            }
        }
        if(ans>n)puts("-1");
        else printf("%d\n",ans);
    }
    return 0;
}

Compiler output:
a.cc:14:5: error: reference to 'data' is ambiguous
   14 |     data mp[110];
      |     ^~~~
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:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:6:16: note:                 'struct data'
    6 |         struct data{
      |                ^~~~
a.cc: In member function 'void Graph::link(int, int)':
a.cc:38:9: error: 'mp' was not declared in this scope; did you mean 'ma'?
   38 |         mp[++cnt].to=y;
      |         ^~
      |         ma
a.cc: In member function 'void Graph::dfs(int, int)':
a.cc:46:31: error: 'mp' was not declared in this scope; did you mean 'ma'?
   46 |         for(int i=head[x];i;i=mp[i].nxt)
      |                               ^~
      |                               ma
a.cc: At global scope:
a.cc:60:9: error: reference to 'data' is ambiguous
   60 |         data mp[110];
      |         ^~~~
/usr/include/c++/14/bits/range_access.h:344:5: note: candidates are: 'template<class _Tp> constexpr const _Tp* std::data(initializer_list<_Tp>)'
  344 |     data(initializer_list<_Tp> __il) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:334:5: note:                 'template<class _Tp, long unsigned int _Nm> constexpr _Tp* std::data(_Tp (&)[_Nm])'
  334 |     data(_Tp (&__array)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:323:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(const _Container&)'
  323 |     data(const _Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:312:5: note:                 'template<class _Container> constexpr decltype (__cont.data()) std::data(_Container&)'
  312 |     data(_Container& __cont) noexcept(noexcept(__cont.data()))
      |     ^~~~
a.cc:6:16: note:                 'struct data'
    6 |         struct data{
      |                ^~~~
a.cc: In function 'void link(int, int)':
a.cc:66:5: error: 'mp' was not declared in this scope
   66 |     mp[++cnt].to=y;
      |     ^~
a.cc: In function 'bool Topsort()':
a.cc:83:31: error: 'mp' was not declared in this scope
   83 |         for(int i=head[u];i;i=mp[i].nxt)
      |                               ^~