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
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#include<iostream>
#include<vector>
#include<queue>
#include<deque>
using namespace std;
typedef long long ll;
queue<int>q;//xd
deque<int>dq;
struct wi{
	vector<int>v;
	__int128 l=0;
	__int128 m=1;
	int iw=0;
	int czy_odw=0;
}*w;
vector<ll>x;
void deefes(int a){
	w[a].czy_odw=1;
	for(int i=0;i<w[a].v.size();i++){
		w[w[a].v[i]].iw++;
		if(w[w[a].v[i]].czy_odw==0)deefes(w[a].v[i]);
	}
	return;
}
__int128 aa,bb,p;
__int128 enwude(){
	if(aa==0||bb==0)return max(aa,bb);
	p=aa;
	aa=bb%aa;
	bb=p;
	return enwude();
}
void topo_sort(int a){
	__int128 xx;
	q.push(a);
	w[a].l=1;
	while(!q.empty()){
		a=q.front();
		q.pop();
		//cout<<a<<' '<<(ll)(w[a].l)<<'/'<<(ll)(w[a].m)<<'\n';
		if(w[a].v.size()==0)continue;
		w[a].m*=w[a].v.size();
		aa=w[a].m;
		bb=w[a].l;
		xx=enwude();
		//cout<<(ll)(w[a].m)<<" i "<<(ll)(w[a].l)<<" -> "<<(ll)(xx)<<'\n';
		w[a].m/=xx;
		w[a].l/=xx;
		x.push_back(w[a].m);
		for(int i=0;i<w[a].v.size();i++){
			w[w[a].v[i]].iw--;
			//cout<<w[a].v[i]<<' ';
			aa=w[w[a].v[i]].m;
			bb=w[a].m;
			xx=enwude();
			//cout<<w[w[a].v[i]].m<<" i "<<w[a].m<<" -> "<<xx<<'\n';
			w[w[a].v[i]].l=w[w[a].v[i]].l*(w[a].m/xx)+w[a].l*(w[w[a].v[i]].m/xx);
			w[w[a].v[i]].m*=(w[a].m/xx);
			aa=w[w[a].v[i]].m;
			bb=w[w[a].v[i]].l;
			xx=enwude();
			//cout<<w[w[a].v[i]].m<<" i "<<w[w[a].v[i]].l<<" -> "<<xx<<'\n';
			w[w[a].v[i]].m/=xx;
			w[w[a].v[i]].l/=xx;
			//cout<<w[a].v[i]<<' '<<w[w[a].v[i]].iw<<'\n';
			if(w[w[a].v[i]].iw==0)q.push(w[a].v[i]);
		}
		//cout<<'\n';
	}
	return;
}
__int128 enwuwu(){
	__int128 il=1;
	for(int i=0;i<x.size();i++){
		aa=il;
		bb=x[i];
		il=(il*x[i])/enwude();
	}
	return il;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
	int n,v1,v2,co;
	__int128 ans;
	ll xd;
	cin>>n;
	w=new wi[n+1];
	for(int i=1;i<=n;i++){
		cin>>v1;
		for(int j=0;j<v1;j++){
			cin>>v2;
			w[i].v.push_back(v2);
			//w[v2].iw++;
		}
	}
	deefes(1);
	topo_sort(1);
	ans=enwuwu();
	while(ans){
		dq.push_front(ans%10);
		ans/=10;
	}
	while(!dq.empty()){
		cout<<dq.front();
		dq.pop_front();
	}
	return 0;
}