Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <cstring>
- #include <algorithm>
- #include <cmath>
- #include <vector>
- #include <set>
- #include <map>
- #include <stack>
- #include <queue>
- #include <deque>
- #include <unordered_map>
- #include <numeric>
- #include <iomanip>
- using namespace std;
- #define pii pair<int , int>
- #define ll long long
- #define FAST ios_base::sync_with_stdio(false); cin.tie(NULL)
- const long long dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
- const long long dl[2] = {1, -1};
- const long long MOD = 1000000007;
- const long long MAXN = 500005;
- int N, Q;
- set<int> s[MAXN];
- int r[MAXN];
- int main() {
- FAST;
- cin >> N >> Q;
- for(int x, i = 1; i <= N; i++){
- r[i] = i;
- cin >> x;
- for(int y, j = 0; j < x; j++){
- cin >> y;
- s[i].insert(y);
- }
- }
- for(int x, y, z, i = 0; i < Q; i++){
- cin >> x;
- if(x == 2){
- cin >> y;
- cout << s[r[y]].size() << "\n";
- }
- else{
- cin >> y >> z;
- if(s[r[y]].size() < s[r[z]].size()){
- s[r[z]].merge(s[r[y]]);
- int temp = r[z];
- r[z] = r[y];
- r[y] = temp;
- s[r[z]].clear();
- }
- else{
- s[r[y]].merge(s[r[z]]);
- s[r[z]].clear();
- }
- }
- }
- }
- /*
- 3 11
- 2 5 1
- 3 2 4 7
- 4 8 5 2 6
- 2 1
- 2 2
- 2 3
- 1 1 3
- 2 1
- 2 3
- 1 2 3
- 2 2
- 1 2 1
- 2 1
- 2 2
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement