#include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; struct UnionFind { vector par; vector siz; UnionFind(int N) : par(N), siz(N) { for(int i = 0; i < N; i++){ par[i] = i; siz[i] = 1; } } int root(int x) { if (par[x] == x) return x; return par[x] = root(par[x]); } void unite(int x, int y) { int rx = root(x); int ry = root(y); if (rx == ry) return; par[rx] = ry; siz[ry] += siz[rx]; } bool same(int x, int y) { int rx = root(x); int ry = root(y); return rx == ry; } int size(int x){ return siz[root(x)]; } }; template using pq = priority_queue, greater>; int main(){ ll N, M, A, B, c, x, y, ans=0; cin >> N >> M; vector> X; for (int i=0; i> A; X.push_back({A, 0}); } for (int i=0; i> B; X.push_back({B, 1}); } sort(X.begin(), X.end()); pq> que; UnionFind tree(N+M+1); for (int i=0; i