logo AlgoBeat OnlineJudge
登录 注册

#215315. [SWERC 2024] Divination

内存限制:2048 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

In Yinxu, the archaeological site of the late capital of the Shang Dynasty, there are divination papers written in oracle bone script, numbered . 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: cites , cites , ..., cites , cites (where ).

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., cites , cites , ..., cites , without any papers missing. Please determine whether these divination papers constitute a complete set.

输入格式

The first line contains an integer , represents the number of papers. Then lines follow, the of them represents the citations of the paper: the first integer represents the number of its citations, followed by integers that represent the papers that it cites.

输出格式

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

样例

样例输入 1

4
0
2 1 4
2 2 4
1 1

样例输出 1

1

样例输入 2

4
0
1 1
2 2 4
1 1

样例输出 2

0

数据范围与提示

Sample Explanation 1

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

Limits

  • ;
  • for all ;
  • ;
  • for all and .
  • for all and .