-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1043.cpp
More file actions
120 lines (95 loc) · 1.84 KB
/
1043.cpp
File metadata and controls
120 lines (95 loc) · 1.84 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#include <bits/stdc++.h>
#include <quadmath.h>
#define vt vector
#define en '\n'
#define ll long long
#define ull unsigned long long
#define ld long double
#define ioa insert_or_assign
#define umap unordered_map
#define prq priority_queue
#define pb push_back
#define pii pair<int,int>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define rev(c) (c).rbegin(), (c).rend()
#define mset(ar, val) memset(ar, val, sizeof(ar))
using namespace std;
const int d4r[4] = {-1,0,1,0}; const int d4c[4] = {0,1,0,-1};
const int d8r[8] = {-1,-1,0,1,1,1,0,-1}; const int d8c[8] = {0,1,1,1,0,-1,-1,-1};
const int INF = 0x3f3f3f3f; const int mINF = 0xc0c0c0c0;
const ll LINF = 0x3f3f3f3f3f3f3f3f; const ll mLINF = 0xc0c0c0c0c0c0c0c0;
int T = 1;
int N,M;
int parent[51];
umap<int,int> u;
int find(int x) {
if(parent[x] == x) {
return x;
}
return parent[x] = find(parent[x]);
}
void merge(int x, int y) {
x = find(x);
y = find(y);
if(x == y) return;
if(u.find(x) != u.end()) {
parent[y] = x;
} else if(u.find(y) != u.end()) {
parent[x] = y;
} else {
if(x < y) parent[y] = x;
else parent[x] = y;
}
}
bool isUnion(int x, int y) {
x = find(x);
y = find(y);
return x == y;
}
void sol() {
cin >> N >> M;
int x; cin >> x;
for(int i=1; i<=N; ++i) parent[i] = i;
for(int i=0,k; i<x; ++i) {
cin >> k;
u[k]++;
}
vt<vt<int>> v;
for(int i=0,k; i<M; ++i) {
cin >> k;
vt<int> a;
int prev;
for(int j=0,p; j<k; ++j) {
cin >> p;
if(j > 0) {
merge(prev, p);
}
prev = p;
a.pb(p);
}
v.pb(a);
}
int ans = 0;
for(int i=0; i<M; ++i) {
bool err = 0;
for(int j=0; j<sz(v[i]); ++j) {
if(u.find(find(v[i][j])) != u.end()) {
err = 1;
break;
}
}
if(!err) {
ans++;
}
}
cout << ans << en;
return;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
while(T--) {
sol();
}
return 0;
}