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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define fi first
#define se second
#define all(x) (x.begin(),x.end())

using namespace std;
const int MAX_N=120;
vector<int> dokad[MAX_N];
ll ile[MAX_N];



int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie();
	ll odp=1;
	int N;
	cin>>N;
	for(int i=1; i<=N; i++){
		int R;
		cin>>R;
		for(int j=1; j<=R; j++){
			int x;
			cin>>x;
			dokad[i].pb(x);
		}
	}
	ile[1]=1;
	for(int i=1; i<=N; i++){
		if(ile[i]==0) continue;
		ll R;
		R=dokad[i].size();
		if(R==0) continue;
		if(ile[i]%R!=0){
			ll M;
			M=R/__gcd(R,ile[i]);
			odp*=M;
			for(int j=1; j<=N; j++){
				ile[j]*=M;
			}
		}
		for(int j=0; j<R; j++){
			ile[dokad[i][j]]+=ile[i]/R;
		}
	}
	cout<<odp<<"\n";
}