from math import gcd n = int(input()) G = [[]] for i in range(1, n+1): G.append(list(map(int, input().split(" ")))[1:]) def spr(x): T = [0]*(n+1) T[1] = x for v in range(1, n+1): d = len(G[v]) if (d == 0): continue if (T[v] % d != 0): return d // gcd(d, T[v]) for u in G[v]: T[u] += T[v] // d return 1 R = 1 r = 2 while r > 1: r = spr(R) R *= r print(R)
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 | from math import gcd n = int(input()) G = [[]] for i in range(1, n+1): G.append(list(map(int, input().split(" ")))[1:]) def spr(x): T = [0]*(n+1) T[1] = x for v in range(1, n+1): d = len(G[v]) if (d == 0): continue if (T[v] % d != 0): return d // gcd(d, T[v]) for u in G[v]: T[u] += T[v] // d return 1 R = 1 r = 2 while r > 1: r = spr(R) R *= r print(R) |