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

n = int(input())

outdeg = [0 for i in range(n + 1)]
to = [[] for i in range(n + 1)]
prod = 1
for i in range(1, n + 1):
  line = input().split(' ')
  outdeg[i] = int(line[0])
  for j in range(1, outdeg[i] + 1):
    to[i].append(int(line[j]))
  if outdeg[i]:
    prod *= outdeg[i]

g = prod
dp = [0 for i in range(n + 1)]
dp[1] = prod
for i in range(1, n + 1):
  if outdeg[i] != 0:
    go = dp[i] // outdeg[i]
    g = math.gcd(g, go)
    for nei in to[i]:
      dp[nei] += go
#print(dp)
print(prod // g)