Language: C++

#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, a[N], b[N];
vector<int> g[N]; 
int tot, dfn[N], fa[N], dep[N], sz[N], son[N], top[N];
void pre(int u) {
  sz[u] = 1;
  for (auto v : g[u]) {
    if (v ^ fa[u]) {
      dep[v] = dep[u] + 1;
      fa[v] = u;
      pre(v);
      sz[u] += sz[v];
      if (sz[son[u]] < sz[v]) {
        son[u] = v;
      }
    }
  }
}
void dfs(int u) {
  if (son[u]) {
    top[son[u]] = top[u];
    dfn[son[u]] = ++tot;
    dfs(son[u]);
  }
  for (auto v : g[u]) {
    if ((v ^ fa[u]) && (v ^ son[u])) {
      top[v] = v;
      dfn[v] = ++tot;
      dfs(v);
    }
  }
}
struct data {
  int val, cnt;
  inline void operator += (const data &rhs) {
    val ^= rhs.val;
    cnt += rhs.cnt;
  }
  inline data operator + (const data &rhs) {
    if (cnt < rhs.cnt) {
      return *this;
    } else {
      return rhs;
    }
  }
}; 
struct node {
  data info, tag;
} t[N << 2];
inline void pushup(int p) {
  t[p].info = t[p << 1].info + t[p << 1 | 1].info;
}
inline void tag(int p, data add) {
  t[p].info += add;
  t[p].tag += add;
}
inline void pushdown(int p) {
  if (t[p].tag.cnt) {
    tag(p << 1, t[p].tag);
    tag(p << 1 | 1, t[p].tag);
    t[p].tag = (data) {0, 0};
  }
}
void modify(int p, int l, int r) {
  if (l == r) {
    t[p].info.cnt = 1e9;
    return;
  }
  pushdown(p);
  int mid = l + r >> 1;
  if (t[p << 1].info.cnt == 1) {
    modify(p << 1, l, mid);
  } else {
    modify(p << 1 | 1, mid + 1, r);
  }
  pushup(p);
}
void modify(int p, int l, int r, int L, int R, data add) {
  if (l >= L && r <= R) {
    tag(p, add);
    return;
  }
  pushdown(p);
  int mid = l + r >> 1;
  if (mid >= L) {
    modify(p << 1, l, mid, L, R, add);
  } 
  if (mid < R) {
    modify(p << 1 | 1, mid + 1, r, L, R, add);
  }
  pushup(p);
}
inline void modify(int u, int v, data add) {
  while (top[u] != top[v]) {
    if (dep[u] < dep[v]) {
      swap(u, v);
    }
    if (u ^ top[u]) {
      modify(1, 1, tot, dfn[top[u]] + 1, dfn[u], add);
    }
    u = fa[top[u]];
  }
  if (u ^ v) {
    if (dep[u] < dep[v]) {
      swap(u, v);
    }
    modify(1, 1, tot, dfn[v] + 1, dfn[u], add);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  pre(1);
  top[1] = 1;
  dfs(1);
  for (int i = 1; i < n; ++i) {
    scanf("%d%d", &a[i], &b[i]);
    modify(a[i], b[i], (data) {i, 1});
  }
  for (int i = 1; i < n; ++i) {
    int cnt = t[1].info.cnt;
    int idx = t[1].info.val;
    if (cnt ^ 1) {
      puts("NO");
      return 0;
    }
    modify(1, 1, tot);
    modify(a[idx], b[idx], (data) {idx, -1});
  }
  puts("YES");
  return 0;
}

Compiler output:
a.cc:50:3: error: reference to 'data' is ambiguous
   50 |   data info, tag;
      |   ^~~~
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:35:8: note:                 'struct data'
   35 | struct data {
      |        ^~~~
a.cc: In function 'void pushup(int)':
a.cc:53:8: error: 'struct node' has no member named 'info'
   53 |   t[p].info = t[p << 1].info + t[p << 1 | 1].info;
      |        ^~~~
a.cc:53:25: error: 'struct node' has no member named 'info'
   53 |   t[p].info = t[p << 1].info + t[p << 1 | 1].info;
      |                         ^~~~
a.cc:53:46: error: 'struct node' has no member named 'info'
   53 |   t[p].info = t[p << 1].info + t[p << 1 | 1].info;
      |                                              ^~~~
a.cc: At global scope:
a.cc:55:24: error: reference to 'data' is ambiguous
   55 | inline void tag(int p, data add) {
      |                        ^~~~
/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:35:8: note:                 'struct data'
   35 | struct data {
      |        ^~~~
a.cc:55:24: error: 'data' has not been declared
   55 | inline void tag(int p, data add) {
      |                        ^~~~
a.cc: In function 'void tag(int, int)':
a.cc:56:8: error: 'struct node' has no member named 'info'
   56 |   t[p].info += add;
      |        ^~~~
a.cc:57:8: error: 'struct node' has no member named 'tag'
   57 |   t[p].tag += add;
      |        ^~~
a.cc: In function 'void pushdown(int)':
a.cc:60:12: error: 'struct node' has no member named 'tag'
   60 |   if (t[p].tag.cnt) {
      |            ^~~
a.cc:61:22: error: 'struct node' has no member named 'tag'
   61 |     tag(p << 1, t[p].tag);
      |                      ^~~
a.cc:62:26: error: 'struct node' has no member named 'tag'
   62 |     tag(p << 1 | 1, t[p].tag);
      |                          ^~~
a.cc:63:10: error: 'struct node' has no member named 'tag'
   63 |     t[p].tag = (data) {0, 0};
      |          ^~~
a.cc:63:17: error: reference to 'data' is ambiguous
   63 |     t[p].tag = (data) {0, 0};
      |                 ^~~~
/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:35:8: note:                 'struct data'
   35 | struct data {
      |        ^~~~
a.cc: In function 'void modify(int, int, int)':
a.cc:68:10: error: 'struct node' has no member named 'info'
   68 |     t[p].info.cnt = 1e9;
      |          ^~~~
a.cc:73:17: error: 'struct node' has no member named 'info'
   73 |   if (t[p << 1].info.cnt == 1) {
      |                 ^~~~
a.cc: At global scope:
a.cc:80:48: error: reference to 'data' is ambiguous
   80 | void modify(int p, int l, int r, int L, int R, data add) {
      |                                                ^~~~
/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:35:8: note:                 'struct data'
   35 | struct data {
      |        ^~~~
a.cc:80:48: error: 'data' has not been declared
   80 | void modify(int p, int l, int r, int L, int R, data add) {
      |                                                ^~~~
a.cc:95:34: error: reference to 'data' is ambiguous
   95 | inline void modify(int u, int v, data add) {
      |                                  ^~~~
/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:35:8: note:                 'struct data'
   35 | struct data {
      |        ^~~~
a.cc:95:34: error: 'data' has not been declared
   95 | inline void modify(int u, int v, data add) {
      |                                  ^~~~
a.cc:95:13: error: redefinition of 'void modify(int, int, int)'
   95 | inline void modify(int u, int v, data add) {
      |             ^~~~~~
a.cc:66:6: note: 'void modify(int, int, int)' previously defined here
   66 | void modify(int p, int l, int r) {
      |      ^~~~~~
a.cc: In function 'int main()':
a.cc:125:25: error: reference to 'data' is ambiguous
  125 |     modify(a[i], b[i], (data) {i, 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:35:8: note:                 'struct data'
   35 | struct data {
      |        ^~~~
a.cc:128:20: error: 'struct node' has no member named 'info'
  128 |     int cnt = t[1].info.cnt;
      |                    ^~~~
a.cc:129:20: error: 'struct node' has no member named 'info'
  129 |     int idx = t[1].info.val;
      |                    ^~~~
a.cc:135:29: error: reference to 'data' is ambiguous
  135 |     modify(a[idx], b[idx], (data) {idx, -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:                 'temp