-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathA1107.cpp
59 lines (57 loc) · 1.15 KB
/
A1107.cpp
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
#include<iostream>
#include<cstdio>
#include<vector>
#include<queue>
#include<functional>
#include<map>
#include<set>
#include<algorithm>
using namespace std;
const int maxn = 1010;
int parent[maxn];
vector<int> v[maxn];
int find(int node)
{
if(parent[node]==node)
return node;
int ans = find(parent[node]);
parent[node] = ans;
return ans;
}
int main()
{
for(int i = 0; i < maxn; i++) {
parent[i] = i;
}
int n;
scanf("%d",&n);
for(int i = 0; i < n; i++){
int m;
scanf("%d: ",&m);
for(int j = 0; j < m; j++) {
int k;
scanf("%d",&k);
if(!v[k].empty()){
parent[find(i)] = find(v[k][0]);
}
v[k].push_back(i);
}
}
set<int> s;
map<int,int> m;
for(int i = 0; i<n;i++){
m[find(i)]++;
}
cout<<m.size();
vector<int> v;
for(map<int,int>::iterator it = m.begin();it!=m.end();it++){
v.push_back(it->second);
}
sort(v.rbegin(),v.rend());
cout<<endl;
for(int i = 0; i < v.size(); i++) {
if(i>0)cout<<" ";
cout<< v[i];
}
cout<<endl;
}