#import numpy def gcd(a,b): if a==0 or b==0: return a+b return gcd(b%a,a) n = int(input()) cnt = [0 for x in range(n+2)] cnt[1] = 1 for i in range(1,n+1): clist = input().split(' ') sz = int(clist[0]) if sz==0 or cnt[i]==0: continue g = sz//gcd(cnt[i],sz) for j in range(1,n+1): cnt[j] *= g vv = cnt[i]//sz for j in range(1,sz+1): cnt[int(clist[j])] += vv print(cnt[1])
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | #import numpy def gcd(a,b): if a==0 or b==0: return a+b return gcd(b%a,a) n = int(input()) cnt = [0 for x in range(n+2)] cnt[1] = 1 for i in range(1,n+1): clist = input().split(' ') sz = int(clist[0]) if sz==0 or cnt[i]==0: continue g = sz//gcd(cnt[i],sz) for j in range(1,n+1): cnt[j] *= g vv = cnt[i]//sz for j in range(1,sz+1): cnt[int(clist[j])] += vv print(cnt[1]) |