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
#!/usr/bin/env python3.9
from fractions import Fraction
from math import lcm

class Platform:
    pass

n = int(input())
Nx = [[int(x)-1 for x in input().split()[1:]] for _ in range(n)]
Px = [[] for _ in range(n)]
for i, nx in enumerate(Nx):
    for x in nx:
        Px[x].append(i)

# print(Px)

A = [Fraction(1,1)]
X = [Fraction(len(Nx[0]), 1)] if Nx[0] else []
for i in range(1, n):
    A.append(sum([A[p]/len(Nx[p]) for p in Px[i]]) if Px[i] else Fraction(0,1))
    if A[-1] and Nx[i]:
        X.append(len(Nx[i]) / A[-1])

# print(A)
# print(X)
R = lcm(*[x.numerator for x in X])
print(R)