-
Notifications
You must be signed in to change notification settings - Fork 0
/
1107.py
35 lines (35 loc) · 844 Bytes
/
1107.py
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
n = int(input())
father = [i for i in range(n+1)]
course = [0*i for i in range(1001)]
root = course.copy()
def findfather(n):
t = n
while n != father[n]:
n = father[n]
while t != father[t]:
z = t
t = father[t]
father[z] = n
return n
def Union(a,b):
fa = findfather(a)
fb = findfather(b)
if fa != fb:
father[fa] = fb
for i in range(1,n+1):
a,*b = input().split()
b = list(map(int,b))
for each in b:
if course[each] == 0:
course[each] = i
else:
Union(i,course[each])
for i in range(1,n+1):
baba = findfather(i)
root[baba] += 1
root = sorted(list(filter(lambda x:x!=0,root)),reverse=True)
print("%d"%len(root))
for i in range(len(root)):
print("%d"%root[i],end='')
if i != len(root)-1:
print(" ",end='')