import math n = int(input()) res = 1 val = [0] * n val[0] = 1 for u in range(n): line = [int(x) for x in input().split(' ')] e = line[0] line = line[1:] if e > 0: mul = e // math.gcd(e, val[u]) res *= mul for i in range(n): val[i] *= mul for v in line: val[v - 1] += val[u] // e print(res)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | import math n = int(input()) res = 1 val = [0] * n val[0] = 1 for u in range(n): line = [int(x) for x in input().split(' ')] e = line[0] line = line[1:] if e > 0: mul = e // math.gcd(e, val[u]) res *= mul for i in range(n): val[i] *= mul for v in line: val[v - 1] += val[u] // e print(res) |