from sys import stdin, stdout from math import gcd s = [int(x) for x in stdin.read().split()] n = s[0] p = 1 graf = [] for i in range(n): m = s[p] p += 1 graf.append([0] * m) for j in range(m): graf[i][j] = s[p]-1 p += 1 prod = 1 op = [0] * n op[0] = 1 for w in range(n): if(len(graf[w]) == 0): continue; v = len(graf[w]) // gcd(len(graf[w]), op[w]) for i in range(n): op[i] *= v prod *= v v = op[w]//len(graf[w]) op[w] = 0 for i in graf[w]: op[i] += v stdout.write(str(prod)+'\n')
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 | from sys import stdin, stdout from math import gcd s = [int(x) for x in stdin.read().split()] n = s[0] p = 1 graf = [] for i in range(n): m = s[p] p += 1 graf.append([0] * m) for j in range(m): graf[i][j] = s[p]-1 p += 1 prod = 1 op = [0] * n op[0] = 1 for w in range(n): if(len(graf[w]) == 0): continue; v = len(graf[w]) // gcd(len(graf[w]), op[w]) for i in range(n): op[i] *= v prod *= v v = op[w]//len(graf[w]) op[w] = 0 for i in graf[w]: op[i] += v stdout.write(str(prod)+'\n') |