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
#include <iostream>
#include <vector>
int ilu[500001];
int main(){
	int n,m,a,k;
	std::vector<std::vector<std::pair<int,bool> > >spo(1);
	std::ios_base::sync_with_stdio(false);
	std::cin>>k>>n;
	ilu[0]=n;
	ilu[1]=-n;
	for(int i=0;i<n;i++)
		spo[0].emplace_back(std::make_pair(0,false));
	for(int i=1;i<k;i++){
		spo.emplace_back(std::vector<std::pair<int,bool> >(0));
		std::cin>>n;
		for(int j=0;j<n;j++){
			std::cin>>a;
			if(a==0){
				spo[i].emplace_back(std::make_pair(i,false));
				ilu[i]++;
				ilu[i+1]--;
			}
			else{
				spo[i].emplace_back(std::make_pair(spo[i-1][a-1].first,false));
				if(spo[i-1][a-1].second){
					ilu[spo[i-1][a-1].first]++;
					ilu[i+1]--;
				}else{
					spo[i-1][a-1].second=true;
					ilu[i]++;
					ilu[i+1]--;
				}
			}
		}
	}
	int res=0;
	int cur=0;
	for(int i=0;i<=k;i++){
		cur+=ilu[i];
		if(cur>res)
			res=cur;
		//std::cout<<cur<<std::endl;
	}
	std::cout<<res<<std::endl;
		
}