#E. [ABC315E] Prerequisites

    Type: Default 1000ms 256MiB

[ABC315E] Prerequisites

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

[ABC315E] Prerequisites

题面翻译

  • NN 本书,第 ii 本书有 CiC_i 本前置读物 Pi,1,Pi,2Pi,ciP_{i,1},P_{i,2}\dots P_{i,c_i}
  • 现在你想读第 11 本书,问在读第 11 本书之前至少还要读哪些书。
  • 输出读它们的顺序,多解输出任意一个由于我们没有SPJ,请输出字典序最小的那个解。
  • 保证有解,1N,Ci2×1051 \le N,\sum C_i \le 2\times 10^5,其他数据在合理范围内。

题目描述

We have N books numbered 1 to N. Book i assumes that you have read Ci books, the j-th of which is book Pi,j: you must read all these Ci​ books before reading book �i. Here, you can read all the books in some order.

You are trying to read the minimum number of books required to read book 1. Print the numbers of the books you must read excluding book 1 in the order they should be read. Under this condition, the set of books to read is uniquely determined.

输入格式

输入格式如下。

N N C1 C_1 P1,1 P_{1,1} \ldots P1,C1 P_{1,C_1} C2 C_2 P2,1 P_{2,1} \ldots P2,C2 P_{2,C_2} \vdots CN C_N PN,1 P_{N,1} \ldots PN,CN P_{N,C_N}

输出格式

输出在可以读第1本书之前的一个读书序列,要求书本数量最少。如果有多个解,请输出字典序最小的那个解。

样例 #1

样例输入 #1

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

样例输出 #1

5 3 4 2

样例 #2

样例输入 #2

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

样例输出 #2

6 5 4 3 2

样例 #3

样例输入 #3

8
1 5
1 6
1 7
1 8
0
0
0
0

样例输出 #3

5

提示

数据范围

  • 2  N  2 × 105 2\ \leq\ N\ \leq\ 2\ \times\ 10^5
  • 0  Ci < N 0\ \leq\ C_i\ <\ N
  • i=1N Ci  2 × 105 \sum_{i=1}^{N}\ C_i\ \leq\ 2\ \times\ 10^5
  • C1  1 C_1\ \geq\ 1
  • 1  Pi,j  N 1\ \leq\ P_{i,j}\ \leq\ N
  • 1  j < k  Ci 1\ \leq\ j\ <\ k\ \leq\ C_i Pi,j  Pi,k P_{i,j}\ \neq\ P_{i,k}

9月19日周二晚上集训赛

Not Attended
Status
Done
Rule
IOI
Problem
8
Start at
2023-9-19 19:00
End at
2023-9-19 21:00
Duration
2 hour(s)
Host
Partic.
30