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
#include <bits/stdc++.h>
#define nl '\n'

using namespace std;

const int MAXN = 5e5+1;

vector<int> days[MAXN], passed[MAXN];
int req[MAXN], freed[MAXN];

int main()
{
	cin.tie(0)->sync_with_stdio(0);
	int k, n1;
	cin>>k>>n1;
	days[1].assign(n1+1, 0);
	passed[1].assign(n1+1, 0);
	req[1] = freed[1] = n1;
	for(int i=2; i<=k; i++){
		int nk;
		cin>>nk;
		req[i] = freed[i] = nk;
		days[i].resize(nk+1, 0);
		passed[i].resize(nk+1, 0);
		for(int j=1; j<=nk; j++){
			cin>>days[i][j];
		}
	}
	int res = 0;
	for(int i=k; i>0; i--){
		for(int j=1; j<(int)days[i].size(); j++){
			if(days[i][j]){
				if(!passed[i][j]){
					passed[i][j]++;
					req[i]--;
				}
				if(!passed[i-1][days[i][j]]){
					freed[i-1]--;
					req[i-1]--;
				}
				passed[i-1][days[i][j]] += passed[i][j];
			}
			req[i] += passed[i][j];
		}
		res = max(res, req[i]);
	}
	/*for(int i=1; i<=k; i++){
		cerr<<req[i]<<' '<<freed[i]<<", ";
		for(auto j: passed[i]){
			cerr<<j<<' ';
		}
		cerr<<nl;
	}*/
	cout<<res<<nl;
	return 0;
}