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
import math 

n = int(input())

D = []
P = []
V = []

for i in range(0,n,1):
	D.append([])
	P.append([])
	V.append(0)

for i in range(0,n,1):
	s = input().split(" ")
	r = int(s[0])
	for j in range(0,r,1):
		D[i].append(int(s[j+1])-1)
		P[D[i][j]].append(i)

V[0] = 1
for i in range(0,n,1):
	if len(D[i]) == 0 : continue

	for p in P[i]:
		V[i] += V[p]//len(D[p])
	if V[i]==0: continue

	pom = int(len(D[i])/math.gcd(V[i],len(D[i])))

	V[0] = V[0] * pom

	for j in range(1,i+1,1):
		V[j] = 0
		for p in P[j]:
			V[j] += V[p]//len(D[p])

print(V[0])