403105: GYM101005 H Control

Memory Limit:28 MB Time Limit:0 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

H. Controltime limit per test0.8 secondsmemory limit per test28 megabytesinputstandard inputoutputstandard output

You are given a directed graph with nodes and edges. You can say that node controls node if you can reach node from node only using the edges in the graph. For each node in the graph, you must print the number of nodes that node controls.

Input

The first line contains (), the number of nodes. lines follow. Each line starts with a number , followed by numbers, representing the nodes that has an edge to. It is guaranteed that the sum of the numbers is less than . Also, there are no more than maximal subsets of nodes such that for any edge in the subset, there is a series of edges connecting with .

Output

You must print numbers on the first line, separated by a blank space, where the th number represents the number of nodes controlled by .

ExampleInput
7
2 5 2
0
1 2
3 3 5 1
2 1 2
3 1 2 3
3 2 5 6
Output
3 1 2 5 3 5 6 

加入题单

算法标签: