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
51
52
53
54
55
56
57
58
59
60
61
#include <bits/stdc++.h>
#define int __int128_t
#define pb push_back
using namespace std;
const int N = 1e3 + 5;
vector<int> kraw[N];
int dp[N], sz[N];
bitset<N> odw;
std::ostream&
operator<<( std::ostream& dest, __int128_t value )
{
    std::ostream::sentry s( dest );
    if ( s ) {
        __uint128_t tmp = value < 0 ? -value : value;
        char buffer[ 128 ];
        char* d = std::end( buffer );
        do
        {
            -- d;
            *d = "0123456789"[ tmp % 10 ];
            tmp /= 10;
        } while ( tmp != 0 );
        if ( value < 0 ) {
            -- d;
            *d = '-';
        }
        int len = std::end( buffer ) - d;
        if ( dest.rdbuf()->sputn( d, len ) != len ) {
            dest.setstate( std::ios_base::badbit );
        }
    }
    return dest;
}
int NWW(int a, int b){
	return a*b/__gcd(a, b);
}
void dfs(int x){
	dp[x]=max((int)1, (int)kraw[x].size());
	for(auto v : kraw[x]){
		dfs(v);
		dp[x]=NWW(dp[x], dp[v]);
	}
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	long long n;
	cin>>n;
	for(int i=1;i<=n;i++){
		long long k;
		cin>>k;
		for(int j=1;j<=k;j++){
			long long a;
			cin>>a;
			kraw[i].pb(a);
		}
	}
	dfs(1);
	cout<<dp[1];
	return 0;
}