#P12566. [UOI 2023] An Array and Several More Arrays

[UOI 2023] An Array and Several More Arrays

题目描述

There are kk arrays of integers a1,a2,,aka_1, a_2, \ldots, a_k, where the array with index ii contains lil_i elements. Let n=l1+l2++lkn = l_1 + l_2 + \ldots + l_k.

You need to find kk integers d1,d2,,dkd_1, d_2, \ldots, d_k such that the numbers (ai,j+di)(a_{i,j} + d_i) are pairwise distinct and satisfy 1ai,j+din1 \leq a_{i,j} + d_i \leq n.

输入格式

The first line contains two integers nn and kk (1n1041 \le n \le 10^4, 1k51 \le k \le 5) -- the total number of elements in the arrays and the number of arrays, respectively.

The next kk lines contain the arrays. The ii-th line contains an integer lil_i (1lin1\le l_i\le n) and lil_i integers ai,1,ai,2,,ai,lia_{i,1},a_{i,2},\ldots,a_{i,l_i} (1ai,jn1 \le a_{i,j} \le n) -- the length and elements of the ii-th array, respectively.

It is guaranteed that n=l1+l2++lkn = l_1 + l_2 + \ldots + l_k.

输出格式

If the required values of dd do not exist, output a single line No.

Otherwise, output Yes on the first line.

On the second line, output kk integers d1,d2,,dkd_1,d_2,\ldots,d_k -- the values that need to be added to the elements of the arrays to form a total of nn distinct integers from 11 to nn.

If there are multiple correct answers, any one of them may be output.

5 5
1 1
1 2
1 3
1 4
1 5
Yes
0 0 0 0 0
6 4
2 2 3
1 6
1 4
2 1 5
Yes
1 -5 1 1
7 2
4 1 4 5 6
3 1 2 6
Yes
0 1
4 2
2 2 3
2 2 4
No

提示

In the first example, d=[0,0,0,0,0]d = [0,0,0,0,0] satisfies the condition, since after adding the corresponding values, the arrays [1][1], [2][2], [3][3], [4][4], [5][5] are formed.

In the second example, d=[1,5,1,1]d = [1,-5,1,1] satisfies the condition, since after adding the corresponding values, the arrays [3,4][3,4], [1][1], [5][5], [2,6][2,6] are formed.

In the third example, d=[0,1]d = [0,1] satisfies the condition, since after adding the corresponding values, the arrays [1,4,5,6][1,4,5,6] and [2,3,7][2,3,7] are formed.

Scoring

  • (88 points): k=1k=1;
  • (99 points): ai,j+1=ai,j+1a_{i,j}+1=a_{i,j+1} for 1ik1 \le i \le k, 1j<li1 \le j < l_i;
  • (1515 points): k2k \le 2;
  • (2121 points): k3k \le 3;
  • (1010 points): ai,j+2=ai,j+1a_{i,j}+2=a_{i,j+1} for 1ik1 \le i \le k, 1j<li1 \le j < l_i;
  • (1010 points): $(\max_{j \in [1;l_i]} a_{i,j}) - (\min_{j \in [1;l_i]} a_{i,j})=(n-k)$ for 1ik1 \le i \le k;
  • (1010 points): n30n \le 30;
  • (1717 points): without additional constraints.