1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
from fractions import Fraction
from math import lcm

n = int(input())

e = [[]] * (n + 1)

for i in range(1, n + 1):
	e[i] = list(map(int, input().split()))[1:]

sz = [Fraction(0, 1)] * (n + 1)
ans = 1
sz[1] = Fraction(1, 1)

for i in range(1, n + 1):
	if len(e[i]) >= 1:
		p = sz[i] / len(e[i])
		ans = lcm(ans, p.denominator)
		for c in e[i]:
			sz[c] += p
print(ans)