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
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<algorithm>
#include<bits/stdc++.h>
#define pr pair
#define f first
#define s second
#define ll long long
#define mp make_pair
#define pll pr<ll,ll>
#define pii pr<int,int>
#define piii pr<int,pii>
using namespace std;
int tl[500005];
bool hd[500005];
int nx[500005];
int pf[500005];
int main()
{
	ios_base::sync_with_stdio(0);
	int n,k;
	cin>>n>>k;
	for(int i=1;i<n;i++)
	{
		int m;
		cin>>m;
		for(int j=0;j<m;j++)
		{
			int x;
			cin>>x;
			x--;
			if(x==-1) nx[j]=i;
			else nx[j]=tl[x],hd[x]=1;
		}
		for(int j=0;j<k;j++) if(!hd[j]) pf[tl[j]]++,pf[i]--;
		for(int j=0;j<m;j++) tl[j]=nx[j],hd[j]=0;
		k=m;
	}
	for(int j=0;j<k;j++) pf[tl[j]]++;
	for(int i=1;i<n;i++) pf[i]+=pf[i-1];
	int mx=0;
	for(int i=0;i<n;i++) mx=max(mx,pf[i]);
	cout<<mx<<endl;
	return 0;
}