F.A.Q
Hand In Hand
Online Acmers
Problem Archive
Realtime Judge Status
Authors Ranklist
 
     C/C++/Java Exams     
ACM Steps
Go to Job
Contest LiveCast
ICPC@China
Best Coder beta
VIP | STD Contests
    DIY | Web-DIY beta
Author ID 
Password 
 Register new ID

Tree

Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 365    Accepted Submission(s): 125


Problem Description
Teacher Mai has a directed graph with n nodes and n edges. This graph is special: Out degree of each node is 1, and there is no self loop.

For every node Teacher Mai wrote down a set of nodes which directly links to this node.

For example, the graph contains 4 edges: {1->2,2->4,3->1,4->1}, the set of each node is {3,4},{1},{},{2}

But Teacher Mai found that he forgot writing which node the set belonged to.

Teacher Mai wanted to recover it, but he found there are many graphs with the same node sets.

You should count the number of different graphs have the same node sets as the given one.

The number can be very large, just output the number modulo 1000000007 (10^9+7).

If there is no solution, the answer is 0.
 

Input
There are multiple test cases, terminated by a line "0".

For each test case, the first line contains a integer n (1<=n<=1000).

The following are n lines representing the set of each node. For every line, there is a integer p first, indicating the size of the set. Then there are p integers, indicating the node with index from 1 to n in this set.
 

Output
For each test case, output one line "Case #k: ans", where k is the case number, counting from 1, ans is the number module 10^9+7.
 

Sample Input
6 1 1 0 0 0 2 2 3 3 4 5 6 0
 

Sample Output
Case #1: 38
 

Author
xudyh
 

Source
 

Statistic | Submit | Discuss | Note
Hangzhou Dianzi University Online Judge 3.0
Copyright © 2005-2024 HDU ACM Team. All Rights Reserved.
Designer & Developer : Wang Rongtao LinLe GaoJie GanLu
Total 0.000000(s) query 1, Server time : 2024-04-25 06:57:48, Gzip enabled