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
n=int(input())
g=[]
h=[[] for i in range(n+1)]
for i in range(n):
    a=list(map(int,input().split()))
    for c in a[1:]:
        h[c].append(i+1)
    g.append(a)
x=1
z=[[1,1]]
h[1].append(0)
for i in range(1,n+1):
    w=0
    for c in h[i]:
        b,p=z[c]
        w+=x*p//b
    r=g[i-1][0]
    v=w
    if w>0 and r>0:   
        while r:
            w,r=r,w%r
        x=x*g[i-1][0]//w
        z.append([x,v//w])
    else:
        z.append([1,0])
print(x)