Language: C++

class UnionFindTree
{
    vector<int> parent;
    vector<int> depth;
    vector<int> cnt;

public:
    UnionFindTree(int n) : parent(n), depth(n), cnt(n)
    {
        for (int i = 0; i < n; i++)
        {
            parent[i] = i;
            depth[i] = 0;
            cnt[i] = 1;
        }
    }

    //木の根を求める
    int find(int x)
    {
        if (parent[x] == x)
        {
            return x;
        }
        else
        {
            return parent[x] = find(parent[x]);
        }
    }

    //xとyの属する集合を併合
    void unite(int x, int y)
    {
        x = find(x);
        y = find(y);
        if (x == y)
            return;
        if (depth[x] < depth[y])
        {
            parent[x] = y;
            cnt[y] += cnt[x];
        }
        else
        {
            parent[y] = x;
            cnt[x] += cnt[y];
            if (depth[x] == depth[y])
                depth[x]++;
        }
    }
    // 同じ集合に属しているか判定
    bool same(int x, int y)
    {
        return find(x) == find(y);
    }
    // 集合のサイズを取得
    int size(int x)
    {
        return cnt[find(x)];
    }
};

Compiler output:
a.cc:3:5: error: 'vector' does not name a type
    3 |     vector<int> parent;
      |     ^~~~~~
a.cc:4:5: error: 'vector' does not name a type
    4 |     vector<int> depth;
      |     ^~~~~~
a.cc:5:5: error: 'vector' does not name a type
    5 |     vector<int> cnt;
      |     ^~~~~~
a.cc: In constructor 'UnionFindTree::UnionFindTree(int)':
a.cc:8:28: error: class 'UnionFindTree' does not have any field named 'parent'
    8 |     UnionFindTree(int n) : parent(n), depth(n), cnt(n)
      |                            ^~~~~~
a.cc:8:39: error: class 'UnionFindTree' does not have any field named 'depth'
    8 |     UnionFindTree(int n) : parent(n), depth(n), cnt(n)
      |                                       ^~~~~
a.cc:8:49: error: class 'UnionFindTree' does not have any field named 'cnt'
    8 |     UnionFindTree(int n) : parent(n), depth(n), cnt(n)
      |                                                 ^~~
a.cc:12:13: error: 'parent' was not declared in this scope
   12 |             parent[i] = i;
      |             ^~~~~~
a.cc:13:13: error: 'depth' was not declared in this scope
   13 |             depth[i] = 0;
      |             ^~~~~
a.cc:14:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   14 |             cnt[i] = 1;
      |             ^~~
      |             int
a.cc: In member function 'int UnionFindTree::find(int)':
a.cc:21:13: error: 'parent' was not declared in this scope
   21 |         if (parent[x] == x)
      |             ^~~~~~
a.cc: In member function 'void UnionFindTree::unite(int, int)':
a.cc:38:13: error: 'depth' was not declared in this scope
   38 |         if (depth[x] < depth[y])
      |             ^~~~~
a.cc:40:13: error: 'parent' was not declared in this scope
   40 |             parent[x] = y;
      |             ^~~~~~
a.cc:41:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   41 |             cnt[y] += cnt[x];
      |             ^~~
      |             int
a.cc:45:13: error: 'parent' was not declared in this scope
   45 |             parent[y] = x;
      |             ^~~~~~
a.cc:46:13: error: 'cnt' was not declared in this scope; did you mean 'int'?
   46 |             cnt[x] += cnt[y];
      |             ^~~
      |             int
a.cc: In member function 'int UnionFindTree::size(int)':
a.cc:59:16: error: 'cnt' was not declared in this scope; did you mean 'int'?
   59 |         return cnt[find(x)];
      |                ^~~
      |                int