#P16540. [EGOI 2026] 披萨大师 / Ovenmasters

    ID: 18913 远端评测题 2000ms 1024MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>Special Judge2026EGOI(欧洲/女生)

[EGOI 2026] 披萨大师 / Ovenmasters

Problem Description

You are a journalist from the “Italian Excellent Pizza Masters Competition”. The best NN pizza chefs in Italy have just competed here to decide who is the greatest pizza master. Each chef baked one pizza, and then the judges ranked the pizzas. Each pizza received a unique rank from 00 (best) to N−1N - 1 (worst). Each chef also received the same rank as their pizza.

After the competition, it is time for the pizza feast. All chefs will attend, and each person brings their own pizza to the feast. The chefs arrive one by one in some order (not necessarily by rank). There are M≤NM \leq N tables at the feast, numbered from 00 to M−1M - 1. The first MM chefs who arrive place their pizzas on tables 00 to M−1M - 1 in arrival order. The remaining N−MN - M chefs want to eat a pizza that is better than the one they made, but not too much better, so they will not feel inferior. Each time a chef arrives, they choose, among the pizzas currently on the tables, the pizza that is better than their own but has the worst rank among those better ones. They sit next to the table of the chosen pizza, eat the entire chosen pizza, and finally leave their own pizza on that table for later chefs (possibly) to eat. If there is no suitable pizza for an arriving chef (because all pizzas on the tables are worse than their own), the chef leaves sadly and takes their own pizza away (that is, they do not leave their pizza).

The example below shows a feast with M=2M = 2 tables, where chefs arrive in the following rank order: 1,0,3,5,4,21, 0, 3, 5, 4, 2. This feast corresponds to the first sample input and output.

:::align{center}

The first M=2M = 2 chefs place their pizzas on the empty tables (00, 11) in arrival order. :::

:::align{center}

Once all tables are occupied, each arriving chef goes to the table that has (under this rule) the pizza that is better than their own but has the worst rank among those better ones (shown by arrows), eats that pizza, and leaves their own. If there is no better pizza, the chef leaves sadly (no arrow). :::

In your article, you want to report the order in which the chefs arrived at the pizza feast. Unfortunately, because you were obsessed with all the tasty pizzas, you forgot to write down their arrival order. Luckily, on each table you can find a stack of trays, which records, in serving order, the pizzas that were served at this table.

:::align{center}

The tray stacks for the first sample. Each stack lists, in arrival order (from bottom to top, where the bottom is earlier), the chefs who ate at this table. The highlighted trays are the pizzas that remained on the tables when the feast ended. :::

You want to use this information to reconstruct the chefs’ arrival order. You realize there may be multiple possible orders, so to get full score you must report the lexicographically smallest valid order.

A sequence a0,a1,…,aN−1a_0, a_1, \dots, a_{N-1} is lexicographically smaller than a sequence b0,b1,…,bN−1b_0, b_1, \dots, b_{N-1} if there exists an index 0≤t<n0 \leq t < n such that for all i<ti < t, ai=bia_i = b_i, and at<bta_t < b_t.

Input Format

The first line contains two integers NN and MM, representing the number of chefs and the number of tables.

Then there are MM lines, each describing the stack of trays on one table. Line ii starts with an integer TiT_i, the number of trays on table ii, followed by TiT_i integers bi,jb_{i, j}, the rank of the jj-th pizza served at this table.

Output Format

If there is no possible order that satisfies the conditions, output NO. If there exists a possible order, output YES. In this case, output a second line containing NN integers a0,a1,⋯ ,aN−1a_0, a_1, \cdots, a_{N-1}, the chefs’ ranks in arrival order. If there are multiple such permutations, you should output the lexicographically smallest one. Note that partially correct answers may still receive points; see the scoring section for details.

6 2
3 1 3 5
2 0 4
YES
1 0 3 5 4 2
6 2
3 1 3 4
2 0 2
NO
4 2
2 0 3
2 1 2
NO
3 1
2 0 2
YES
0 2 1
8 1
8 7 6 5 4 3 2 1 0
NO
12 4
3 2 3 4
1 5
1 6
5 7 8 9 10 11
YES
2 5 6 7 0 1 3 4 8 9 10 11

Hint

Sample Explanation

The first sample input and output correspond to the pictures in the statement.

In particular, in Figures 1 and 2, the arrival order of the chefs is the lexicographically smallest valid arrival order: 1,0,3,5,4,21, 0, 3, 5, 4, 2.

In the second sample, the tray stacks are impossible, because there is no arrival order that makes the chef ranked 5 leave sadly. Therefore, the answer is NO.

In the third and fifth samples, the tray stacks are also impossible (no arrival order can produce them), so the answer is NO.

In the fourth sample (N=3N=3, M=1M=1), there is only one possible arrival order: 0,2,10, 2, 1.

In the sixth sample (N=12N=12, M=4M=4), note that the numbers 00 and 11 do not appear among the values bi,jb_{i,j}. This means that at some time during the feast, both chefs 00 and 11 left sadly. The sample output shows the lexicographically smallest valid arrival order. Of course, there are other valid arrival orders; for example, 2,5,6,7,8,1,3,4,9,10,11,02, 5, 6, 7, 8, 1, 3, 4, 9, 10, 11, 0. Outputting YES followed by any other valid order (instead of the lexicographically smallest one) will be considered partially correct, with a score of 40%.

Constraints

  • 1≤M≤N≤300 0001 \leq M \leq N \leq 300\ 000。
  • 0≤bi,j≤N−10 \leq b_{i,j} \leq N-1。
  • All bi,jb_{i, j} are distinct.
  • 1≤Ti≤N1 \leq T_i \leq N。

Scoring

Your program will be tested on testdata divided into several subtasks. To get the score for a subtask, you must solve all testdata in that subtask correctly.

A solution that only answers the first line (YES or NO) correctly gets 20% of the points. A solution that answers the first line correctly and outputs any valid order (when the answer is YES) gets an additional 20%. To get the remaining 60%, you must output the lexicographically smallest valid order when the first line is YES.

  • Subtask 0 [00 points]: Samples.
  • Subtask 1 [2020 points]: M=1M = 1.
  • Subtask 2 [1010 points]: M=2,N≤200M = 2, N \le 200, and the sum of all TiT_i is NN (in other words, no chef leaves sadly).
  • Subtask 3 [2020 points]: M≤N≤200M \le N \le 200, and the sum of all TiT_i is NN (in other words, no chef leaves sadly).
  • Subtask 4 [2020 points]: M≤10M \le 10.
  • Subtask 5 [3030 points]: No additional constraints.

Translated by ChatGPT 5