403105: GYM101005 H Control
Description
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.
InputThe 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 .
OutputYou must print numbers on the first line, separated by a blank space, where the th number represents the number of nodes controlled by .
ExampleInput7Output
2 5 2
0
1 2
3 3 5 1
2 1 2
3 1 2 3
3 2 5 6
3 1 2 5 3 5 6