Language: C++

#include <bits/stdc++.h>
using namespace std;

class UF {
public:
    int par[200000];
    int r[200000];
    UF (int N) {
        for (int i = 0; i < N; i++) {
            par[i] = i;
        }
    }

    int find(int x) {
        if (x == par[x]) return x;

        return par[x] = find(par[x]);
    }

    void add(int x, int y) {
        x = find(x);
        y = find(y);
        if (x == y) return;

        if (r[x] < r[y]) par[x] = y;
        else {
            par[y] = x;
            if (r[x] == r[y]) r[x]++;
        }
    }
};

int main() {
    int N, K, L;
    cin >> N >> K >> L;

    vector<vector<int> > md(N);
    vector<vector<int> > mt(N);

    vector<pair<int,int> > dP(K), tP(L);

    for (int i = 0; i < K; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        dP[i] = pair<int,int>(min(x, y), max(x, y));
    }

    for (int i = 0; i < L; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        tP[i] = pair<int,int>(min(x, y), max(x, y));
    }

    UF duf(N), tuf(N);

    for (int i = 0; i < K; i++) {
        duf.add(dP[i].first, dP[i].second);
    }

    for (int i = 0; i < L; i++) {
        tuf.add(tP[i].first, tP[i].second);
    }

    UF uf(N);
    for (int i = 0; i < K; i++) {
        if (tuf.find(dP[i].first) == tuf.find(dP[i].second)) {
            uf.add(dP[i].first, dP[i].second);
        }
    }
    for (int i = 0; i < L; i++) {
        if (duf.find(tP[i].first) == duf.find(tP[i].second)) {
            uf.add(tP[i].first, tP[i].second);
        }
    }

    vector<vector<int> > tmp(N);
    for (int i = 0; i < N; i++) {
        tmp[duf.find(i)].push_back(i);
    }

    vector<int> pcount(N);
    for (int i = 0; i < N; i++) {
        map<int,int> count(N);
        for (int j = 0; j < tmp[i].size(); j++) {
            count[tuf.find(tmp[i][j])]++;
        }

        for (int j = 0; j < tmp[i].size(); j++) {
            pcount[tmp[i][j]] += count[tuf.find(tmp[i][j])];
        }
    }

    for (int i = 0; i < N-1; i++) {
        cout << pcount[i] << " ";
    }

    cout << pcount[N-1] << endl;

    return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:85:29: error: no matching function for call to 'std::map<int, int>::map(int&)'
   85 |         map<int,int> count(N);
      |                             ^
In file included from /usr/include/c++/14/map:63,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:152,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_map.h:302:9: note: candidate: 'template<class _InputIterator> std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator, const _Compare&, const allocator_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  302 |         map(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_map.h:302:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:285:9: note: candidate: 'template<class _InputIterator> std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  285 |         map(_InputIterator __first, _InputIterator __last)
      |         ^~~
/usr/include/c++/14/bits/stl_map.h:285:9: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:268:9: note: candidate: 'template<class _InputIterator> std::map<_Key, _Tp, _Compare, _Alloc>::map(_InputIterator, _InputIterator, const allocator_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  268 |         map(_InputIterator __first, _InputIterator __last,
      |         ^~~
/usr/include/c++/14/bits/stl_map.h:268:9: note:   candidate expects 3 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:262:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(std::initializer_list<std::pair<const _Key, _Val> >, const allocator_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; allocator_type = std::allocator<std::pair<const int, int> >]'
  262 |       map(initializer_list<value_type> __l, const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:262:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:256:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(std::map<_Key, _Tp, _Compare, _Alloc>&&, std::__type_identity_t<_Alloc>&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; std::__type_identity_t<_Alloc> = std::allocator<std::pair<const int, int> >]'
  256 |       map(map&& __m, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:256:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:252:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp, _Compare, _Alloc>&, std::__type_identity_t<_Alloc>&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; std::__type_identity_t<_Alloc> = std::allocator<std::pair<const int, int> >]'
  252 |       map(const map& __m, const __type_identity_t<allocator_type>& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:252:7: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_map.h:248:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(const allocator_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; allocator_type = std::allocator<std::pair<const int, int> >]'
  248 |       map(const allocator_type& __a)
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:248:33: note:   no known conversion for argument 1 from 'int' to 'const std::map<int, int>::allocator_type&' {aka 'const std::allocator<std::pair<const int, int> >&'}
  248 |       map(const allocator_type& __a)
      |           ~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:240:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(std::initializer_list<std::pair<const _Key, _Val> >, const _Compare&, const allocator_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; allocator_type = std::allocator<std::pair<const int, int> >]'
  240 |       map(initializer_list<value_type> __l,
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:240:40: note:   no known conversion for argument 1 from 'int' to 'std::initializer_list<std::pair<const int, int> >'
  240 |       map(initializer_list<value_type> __l,
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/14/bits/stl_map.h:227:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(std::map<_Key, _Tp, _Compare, _Alloc>&&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  227 |       map(map&&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:227:11: note:   no known conversion for argument 1 from 'int' to 'std::map<int, int>&&'
  227 |       map(map&&) = default;
      |           ^~~~~
/usr/include/c++/14/bits/stl_map.h:219:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(const std::map<_Key, _Tp, _Compare, _Alloc>&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  219 |       map(const map&) = default;
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:219:11: note:   no known conversion for argument 1 from 'int' to 'const std::map<int, int>&'
  219 |       map(const map&) = default;
      |           ^~~~~~~~~~
/usr/include/c++/14/bits/stl_map.h:206:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map(const _Compare&, const allocator_type&) [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >; allocator_type = std::allocator<std::pair<const int, int> >]'
  206 |       map(const _Compare& __comp,
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:206:27: note:   no known conversion for argument 1 from 'int' to 'const std::less<int>&'
  206 |       map(const _Compare& __comp,
      |           ~~~~~~~~~~~~~~~~^~~~~~
/usr/include/c++/14/bits/stl_map.h:197:7: note: candidate: 'std::map<_Key, _Tp, _Compare, _Alloc>::map() [with _Key = int; _Tp = int; _Compare = std::less<int>; _Alloc = std::allocator<std::pair<const int, int> >]'
  197 |       map() = default;
      |       ^~~
/usr/include/c++/14/bits/stl_map.h:197:7: note:   candidate expects 0 arguments, 1 provided