Language: C++

#include <iostream>
using namespace std;

constexpr int nax = 2e5, no_of_dims = 2;

int n, siz[no_of_dims], id[no_of_dims][nax + 1];
array< int, no_of_dims > spoj[nax + 1];
vector< int > gr[no_of_dims][nax + 1];

bool operator<(const array< int, no_of_dims >& mn, const array< int, no_of_dims >& wc)
{
    for (int i = 0; i < no_of_dims; ++i)
        if (mn[i] < wc[i])
            return true;
    return false;
}

bool operator==(const array< int, no_of_dims >& a, const array< int, no_of_dims >& b)
{
    for (int i = 0; i < no_of_dims; ++i)
        if (a[i] != b[i])
            return false;
    return true;
}

void dfs(const int d, const int v, const int c)
{
    spoj[v][d] = c;
    for (int s : gr[d][v])
        if (not spoj[s][d])
            dfs(d, s, c);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> n;

    for (int i = 0; i < no_of_dims; ++i)
        cin >> siz[i];

    for (int i = 0; i < no_of_dims; ++i)
        for (int j = 0; j < siz[i]; ++j)
        {
            int p, q; cin >> p >> q;
            gr[i][p].push_back(q);
            gr[i][q].push_back(p);
        }

    for (int i = 0; i < no_of_dims; ++i)
        for (int j = 1; j <= n; ++j)
            if (not spoj[j][i])
                dfs(i, j, j);

    sort(begin(spoj) + 1, begin(spoj) + n + 1);

    int current = 0;
    long long result = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (i == 1 or spoj[i] == spoj[i - 1])
            ++current;
        else
        {
            result += (ll)current * (current - 1) / 2;
            current = 1;
        }
    }

    result += (ll)current * (current - 1) / 2;

    cout << result << '\n';
}


Compiler output:
a.cc:7:26: error: elements of array 'std::array<int, 2> spoj [200001]' have incomplete type
    7 | array< int, no_of_dims > spoj[nax + 1];
      |                          ^~~~
a.cc:7:26: error: storage size of 'spoj' isn't known
a.cc:8:1: error: 'vector' does not name a type
    8 | vector< int > gr[no_of_dims][nax + 1];
      | ^~~~~~
a.cc: In function 'bool operator<(const std::array<int, 2>&, const std::array<int, 2>&)':
a.cc:13:15: error: no match for 'operator[]' (operand types are 'const std::array<int, 2>' and 'int')
   13 |         if (mn[i] < wc[i])
      |               ^
a.cc:13:23: error: no match for 'operator[]' (operand types are 'const std::array<int, 2>' and 'int')
   13 |         if (mn[i] < wc[i])
      |                       ^
a.cc: In function 'bool operator==(const std::array<int, 2>&, const std::array<int, 2>&)':
a.cc:21:14: error: no match for 'operator[]' (operand types are 'const std::array<int, 2>' and 'int')
   21 |         if (a[i] != b[i])
      |              ^
a.cc:21:22: error: no match for 'operator[]' (operand types are 'const std::array<int, 2>' and 'int')
   21 |         if (a[i] != b[i])
      |                      ^
a.cc: In function 'void dfs(int, int, int)':
a.cc:29:18: error: 'gr' was not declared in this scope
   29 |     for (int s : gr[d][v])
      |                  ^~
a.cc: In function 'int main()':
a.cc:47:13: error: 'gr' was not declared in this scope
   47 |             gr[i][p].push_back(q);
      |             ^~
a.cc:56:5: error: 'sort' was not declared in this scope; did you mean 'short'?
   56 |     sort(begin(spoj) + 1, begin(spoj) + n + 1);
      |     ^~~~
      |     short
a.cc:66:24: error: 'll' was not declared in this scope
   66 |             result += (ll)current * (current - 1) / 2;
      |                        ^~
a.cc:71:16: error: 'll' was not declared in this scope
   71 |     result += (ll)current * (current - 1) / 2;
      |                ^~