#P15155. [SWERC 2024] Divination
[SWERC 2024] Divination
题目描述
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.
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 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 .