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

x = 1

A = [0]*101
B = [1]*101

A[0] = 1

n = int(input())
for i in range(0,n):
    edges = [int(a) for a in input().split()]
    r = edges[0]

    for j in range(0,r):
        k = edges[j+1]-1

        a = A[i]
        b = B[i]*r

        c = A[k]*b+a*B[k]
        d = b*B[k]
        e = math.gcd(c,d)
        A[k] = c//e
        B[k] = d//e

    if r > 0:
        a = A[i]
        b = B[i]*r
        d = math.gcd(a,b)
        x = math.lcm(x, b//d)

print(x)