1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<functional>
#include<cstdbool>
#include<stack>
#include<vector>
using namespace std;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define INF 987654321
#define LINF 321321321321
#define MAX 1100
 
int parent[1001000];
int n,m;
 
int t;
int True[60];
vector<int> party[61];
void init() {
    for (int i = 1; i <= n; i++) {
        parent[i] = i;
    }
}
 
int Find(int s) {
 
    if (parent[s] == s)
        return s;
    return parent[s] = Find(parent[s]);
}
 
 
void Merge(int a, int b) {
 
    a = Find(a);
    b = Find(b);
 
    if (a < b) {
        parent[b] = a;
    }
    else
        parent[a] = b;
}
 
 
int main(void) {
    
    cin >> n >> m;
    init();
    cin >> t;
 
    for (int i = 0; i < t; i++) {
        cin >> True[i];
    }
    for (int i = 0; i < m; i++) {
        int cnt;
        cin >> cnt;
        int tmp;
        for (int j = 0; j < cnt; j++) {
            cin >> tmp;
            party[i].push_back(tmp);
            if (j >= 1) {
                Merge(party[i][j - 1], party[i][j]);
            }
        }
    }
    int answer = 0;
    for (int i = 0; i < m; i++) {
        int cnt = party[i].size();
        bool flag = true;
        for (int j = 0; j < cnt; j++) {
            int tmp = Find(party[i][j]);
            for (int i = 0; i < t; i++) {
                if (tmp == Find(True[i])) {
                    flag = false;
                    break;
                }
            }
            if (!flag)
                break;
        }
        if (flag)
            answer++;
    }
    cout << answer;
    return 0;
}
 
 
cs

출처: https://www.acmicpc.net/problem/1043

+ Recent posts