#P15155. [SWERC 2024] Divination

[SWERC 2024] Divination

题目描述

In Yinxu, the archaeological site of the late capital of the Shang Dynasty, there are NN divination papers written in oracle bone script, numbered 1,2,...,N1, 2, ..., N. Some papers may cite other papers, but no paper can cite itself. Additionally, there are no circular citations, meaning it's not possible to see the following situation: A1A_1 cites A2A_2, A2A_2 cites A3A_3, ..., AK1A_{K-1} cites AKA_K, AKA_K cites A1A_1 (where 2KN2 \leq K \leq N).

As per myth, a complete set of divination papers can predict the wars and peace of the next century, and it should have a complete citation chain, i.e., A1A_1 cites A2A_2, A2A_2 cites A3A_3, ..., AN1A_{N-1} cites ANA_N, without any papers missing. Please determine whether these NN divination papers constitute a complete set.

输入格式

The first line contains an integer NN, represents the number of papers. Then NN lines follow, the ithi^{th} of them represents the citations of the ithi^{th} paper: the first integer cic_i represents the number of its citations, followed by cic_i integers pi,1,pi,2,...,pi,cip_{i,1}, p_{i,2}, ..., p_{i,c_i} that represent the papers that it cites.

输出格式

A single integer, 11 if they constitute a complete set of divination papers, or 00 otherwise.

4
0
2 1 4
2 2 4
1 1
1
4
0
1 1
2 2 4
1 1
0

提示

Sample Explanation 1

In this sample, paper 33 cites paper 22, paper 22 cites paper 44, paper 44 cites paper 11. Thus, we find a complete citation chain, which makes them a complete set of divination papers.

Limits

  • 2N1000002 \leq N \leq 100000;
  • 0ciN10 \leq c_i \leq N-1 for all iNi \leq N;
  • 0c1+c2+...+cN5000000 \leq c_1 + c_2 + ... + c_N \leq 500000;
  • 1pi,jN1 \leq p_{i,j} \leq N for all iNi \leq N and jcij \leq c_i.
  • pi,jip_{i,j} \neq i for all iNi \leq N and jcij \leq c_i.