logo AlgoBeat OnlineJudge
登录 注册

#213434. [GCJ 2012 #1C] Diamond Inheritance

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

题目描述

You are asked to help diagnose class diagrams to identify instances of diamond inheritance. The following example class diagram illustrates the property of diamond inheritance. There are four classes: and . An arrow pointing from to indicates that class inherits from class .

In this class diagram, inherits from both and , inherits from , and also inherits from . An inheritance path from to is defined as a sequence of classes , , , , , , where inherits from , inherits from for , and inherits from . There are two inheritance paths from to in the example above. The first path is , , and the second path is , , .

A class diagram is said to contain a diamond inheritance if there exists a pair of classes and such that there are at least two different inheritance paths from to . The above class diagram is a classic example of diamond inheritance. Your task is to determine whether or not a given class diagram contains a diamond inheritance.

输入格式

The first line of the input gives the number of test cases, . test cases follow, each specifies a class diagram. The first line of each test case gives the number of classes in this diagram, . The classes are numbered from to . lines follow. The line starts with a non-negative integer indicating the number of classes that class inherits from. This is followed by distinct positive integers each from to representing those classes. You may assume that:

  • If there is an inheritance path from to then there is no inheritance path from to .
  • A class will never inherit from itself.

输出格式

For each diagram, output one line containing "Case #: ", where is the case number (starting from ) and is "Yes" if the class diagram contains a diamond inheritance, "No" otherwise.

样例

样例输入 1

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

样例输出 1

Case #1: No
Case #2: Yes
Case #3: Yes

数据范围与提示

Limits

  • .
  • .

Test set 1 (14 Pts, Visible Verdict)

  • .

Test set 2 (14 Pts, Hidden Verdict)

  • .