import math n = int(input()) G = [] for i in range(0,n): cur = list(map(int,input().split())) cur.pop(0) for i in range(0,len(cur)): cur[i]-=1 G.append(cur) dp = [] for i in range(0,n): dp.append(0) ans = 1 dp[0]=1 for i in range(0,n): if len(G[i])==0: continue g = math.gcd(len(G[i]),dp[i]) #print(str(i)+' '+str(len(G[i]))+' '+str(dp[i])) mult=len(G[i])//g ans*=mult #print(mult) for j in range(i,n): dp[j]*=mult add=dp[i]//len(G[i]) for to in G[i]: dp[to]+=add print(ans)
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 29 30 31 32 | import math n = int(input()) G = [] for i in range(0,n): cur = list(map(int,input().split())) cur.pop(0) for i in range(0,len(cur)): cur[i]-=1 G.append(cur) dp = [] for i in range(0,n): dp.append(0) ans = 1 dp[0]=1 for i in range(0,n): if len(G[i])==0: continue g = math.gcd(len(G[i]),dp[i]) #print(str(i)+' '+str(len(G[i]))+' '+str(dp[i])) mult=len(G[i])//g ans*=mult #print(mult) for j in range(i,n): dp[j]*=mult add=dp[i]//len(G[i]) for to in G[i]: dp[to]+=add print(ans) |