#P15978. [PA 2026] 研讨会 / Konferencja

[PA 2026] 研讨会 / Konferencja

Problem Description

A grand academic conference is held in Bajtocja and lasts for kk days. Each day, several talks are held simultaneously (at the same time). Also, some talks are continuations of talks from the previous day.

Each participant can attend at most one talk per day. Moreover, if talk bb is a continuation of talk aa, then a participant can attend talk bb only if they attended talk aa the day before. A talk can be a continuation of at most one talk from the previous day, but multiple talks may be continuations of the same talk (their participants split into several groups on the next day, and some people may not attend any continuation talk).

The King of Bajtocja wants to know exactly what happens at every talk, so he decides to send his trusted staff to attend the talks. Help him determine the minimum number of staff members that must be sent so that every talk has at least one staff member attending.

Input Format

The first line of input contains two positive integers kk and n1n_1 (1≤k,n1≤500 0001 \le k, n_1 \le 500\,000), representing the number of days of the conference and the number of talks held on the first day (since it is the first day, no talk can be a continuation of an earlier talk).

Next, if k>1k > 1, then for 2≤i≤k2 \le i \le k, line ii contains the description of day ii. The line starts with a positive integer nin_i (1≤ni≤500 0001 \le n_i \le 500\,000), the number of talks held on day ii, followed by nin_i integers ai,1,…,ai,nia_{i,1}, \dots, a_{i,n_i} (0≤ai,j≤ni−10 \le a_{i,j} \le n_{i-1}). ai,j=0a_{i,j} = 0 means that the jj-th talk on day ii is not a continuation of any earlier talk; if ai,j>0a_{i,j} > 0, then the jj-th talk on day ii is a continuation of the ai,ja_{i,j}-th talk on day i−1i-1.

The talks on each day are numbered from 11 to nin_i. The total number of talks, i.e., the sum of all nin_i, does not exceed 500 000500\,000.

Output Format

Output one line containing one integer, the answer.

4 3
3 1 1 1
4 0 0 2 0
2 3 3
6

Hint

Explanation of the sample: We send six staff members to the talks, call them A, B, C, D, E, and F. On the first day, send A, B, C, and D to attend the first talk, E to attend the second talk, and F to attend the third talk.

On the second day, E and F stay at home (there is no talk they can attend), A and B attend the second talk, and C and D attend the first and the third talks, respectively.

On the third day, A and B attend the third talk; for each of the other talks, we send one of the remaining staff members.

On the last day, A and B attend the first and the second talks, respectively.

It can be verified that five staff members cannot cover all talks.

Translated by ChatGPT 5