#include <bits/stdc++.h>
#define pb push_back
const int MAX = 1e6+7;
using namespace std;
vector<int> adj[MAX];
int vis[MAX];
int parent[MAX];
int find(int x){
if(parent[x] != x) parent[x] = find(parent[x]);
return parent[x];
}
void merge(int a, int b){
parent[b] = a;
}
void solve(void){
int n, m;
cin >> n >> m;
for(int i= 1; i<= m; i++){
parent[i] = i;
}
bool pretest_four = false;
for(int i = 1 ; i <= n; i++){
int k;
cin >> k;
if(k) pretest_four = true;
int prev = -1;
for(int i = 0; i < k; i++){
int language;
cin >> language;
if(prev != -1){
if(find(prev) == find(language)){
continue;
}
else{
merge(prev, language);
}
}
prev = language;
}
}
int cc = 0;
for(int i = 1; i <= n; i++){
if(parent[i] == i){
cc++;
}
}
if(!pretest_four){
cout << n ;
return;
}
cout << cc-1;
}
signed main() {
fio;
int t = 1;
// cin>>t;
while(t--)
solve();
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcGIgcHVzaF9iYWNrCmNvbnN0IGludCBNQVggPSAxZTYrNzsKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnZlY3RvcjxpbnQ+IGFkaltNQVhdOwppbnQgdmlzW01BWF07CmludCBwYXJlbnRbTUFYXTsKCmludCBmaW5kKGludCB4KXsKICAgIGlmKHBhcmVudFt4XSAhPSB4KSBwYXJlbnRbeF0gPSBmaW5kKHBhcmVudFt4XSk7CiAgICByZXR1cm4gcGFyZW50W3hdOwp9Cgp2b2lkIG1lcmdlKGludCBhLCBpbnQgYil7CiAgICBwYXJlbnRbYl0gPSBhOyAKfQoKdm9pZCBzb2x2ZSh2b2lkKXsKICAgIGludCBuLCBtOwogICAgY2luID4+IG4gPj4gbTsKICAgIGZvcihpbnQgaT0gMTsgaTw9IG07IGkrKyl7CiAgICAgICAgcGFyZW50W2ldID0gaTsKICAgIH0KCiAgICBib29sIHByZXRlc3RfZm91ciA9IGZhbHNlOwogICAgZm9yKGludCBpID0gMSA7IGkgPD0gbjsgaSsrKXsKICAgICAgICBpbnQgazsKICAgICAgICBjaW4gPj4gazsKICAgICAgICBpZihrKSBwcmV0ZXN0X2ZvdXIgPSB0cnVlOwogICAgICAgIGludCBwcmV2ID0gLTE7CiAgICAgICAgZm9yKGludCBpID0gMDsgaSA8IGs7IGkrKyl7CiAgICAgICAgICAgIGludCBsYW5ndWFnZTsKICAgICAgICAgICAgY2luID4+IGxhbmd1YWdlOwogICAgICAgICAgICBpZihwcmV2ICE9IC0xKXsKICAgICAgICAgICAgICAgIGlmKGZpbmQocHJldikgPT0gZmluZChsYW5ndWFnZSkpewogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgZWxzZXsKICAgICAgICAgICAgICAgICAgICBtZXJnZShwcmV2LCBsYW5ndWFnZSk7CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgcHJldiA9IGxhbmd1YWdlOwogICAgICAgIH0KICAgIH0KCiAgICBpbnQgY2MgPSAwOwogICAgZm9yKGludCBpID0gMTsgaSA8PSBuOyBpKyspewogICAgICAgIGlmKHBhcmVudFtpXSA9PSBpKXsKICAgICAgICAgICAgY2MrKzsKICAgICAgICB9CiAgICB9CgogICAgaWYoIXByZXRlc3RfZm91cil7CiAgICAgICAgY291dCA8PCBuIDsKICAgICAgICByZXR1cm47CiAgICB9CgogICAgY291dCA8PCBjYy0xOwoKfQpzaWduZWQgbWFpbigpIHsKZmlvOwppbnQgdCA9IDE7Ci8vIGNpbj4+dDsKICAgIHdoaWxlKHQtLSkKICAgIHNvbHZlKCk7CgogICAgcmV0dXJuIDA7Cn0K
Main.java:1: error: illegal character: '#'
#include <bits/stdc++.h>
^
Main.java:1: error: class, interface, or enum expected
#include <bits/stdc++.h>
^
Main.java:2: error: illegal character: '#'
#define pb push_back
^
Main.java:4: error: class, interface, or enum expected
using namespace std;
^
Main.java:6: error: class, interface, or enum expected
vector<int> adj[MAX];
^
Main.java:7: error: class, interface, or enum expected
int vis[MAX];
^
Main.java:8: error: class, interface, or enum expected
int parent[MAX];
^
Main.java:10: error: class, interface, or enum expected
int find(int x){
^
Main.java:12: error: class, interface, or enum expected
return parent[x];
^
Main.java:13: error: class, interface, or enum expected
}
^
Main.java:17: error: class, interface, or enum expected
}
^
Main.java:21: error: class, interface, or enum expected
cin >> n >> m;
^
Main.java:22: error: class, interface, or enum expected
for(int i= 1; i<= m; i++){
^
Main.java:22: error: class, interface, or enum expected
for(int i= 1; i<= m; i++){
^
Main.java:22: error: class, interface, or enum expected
for(int i= 1; i<= m; i++){
^
Main.java:24: error: class, interface, or enum expected
}
^
Main.java:27: error: class, interface, or enum expected
for(int i = 1 ; i <= n; i++){
^
Main.java:27: error: class, interface, or enum expected
for(int i = 1 ; i <= n; i++){
^
Main.java:27: error: class, interface, or enum expected
for(int i = 1 ; i <= n; i++){
^
Main.java:29: error: class, interface, or enum expected
cin >> k;
^
Main.java:30: error: class, interface, or enum expected
if(k) pretest_four = true;
^
Main.java:31: error: class, interface, or enum expected
int prev = -1;
^
Main.java:32: error: class, interface, or enum expected
for(int i = 0; i < k; i++){
^
Main.java:32: error: class, interface, or enum expected
for(int i = 0; i < k; i++){
^
Main.java:32: error: class, interface, or enum expected
for(int i = 0; i < k; i++){
^
Main.java:34: error: class, interface, or enum expected
cin >> language;
^
Main.java:35: error: class, interface, or enum expected
if(prev != -1){
^
Main.java:38: error: class, interface, or enum expected
}
^
Main.java:41: error: class, interface, or enum expected
}
^
Main.java:44: error: class, interface, or enum expected
}
^
Main.java:48: error: class, interface, or enum expected
for(int i = 1; i <= n; i++){
^
Main.java:48: error: class, interface, or enum expected
for(int i = 1; i <= n; i++){
^
Main.java:48: error: class, interface, or enum expected
for(int i = 1; i <= n; i++){
^
Main.java:51: error: class, interface, or enum expected
}
^
Main.java:56: error: class, interface, or enum expected
return;
^
Main.java:57: error: class, interface, or enum expected
}
^
Main.java:61: error: class, interface, or enum expected
}
^
Main.java:64: error: class, interface, or enum expected
int t = 1;
^
Main.java:66: error: class, interface, or enum expected
while(t--)
^
Main.java:69: error: class, interface, or enum expected
return 0;
^
Main.java:70: error: class, interface, or enum expected
}
^
41 errors