1107 Social Clusters (30 point(s))
When register on a social network, you are always asked to specify your hobbies in order to find some potential friends with the same hobbies. A social cluster is a set of people who have some of their hobbies in common. You are supposed to find all the clusters.
Input Specification:
Each input file contains one test case. For each test case, the first line contains a positive integer N (≤1000), the total number of people in a social network. Hence the people are numbered from 1 to N. Then N lines follow, each gives the hobby list of a person in the format:
Ki: hi[1] hi[2] ... hi[Ki]
where Ki (>0) is the number of hobbies, and hi[j] is the index of the j-th hobby, which is an integer in [1, 1000].
Output Specification:
For each case, print in one line the total number of clusters in the network. Then in the second line, print the numbers of people in the clusters in non-increasing order. The numbers must be separated by exactly one space, and there must be no extra space at the end of the line.
Sample Input:
Sample Output:
经验总结:
emmmm 经典的并查集题目,这里要注意一点对于所有的人,都要进行两两判定是否有相同的爱好(除了自己和自己),如果有相同的爱好,就要合并,关于并查集的部分,是最基础的并查集的合并与查找,最后再统计群体的个数以及各个群体内部的人数就行了~
AC代码