import sys
from collections import deque, defaultdict

def bfs(graph, start, visited):
    queue = deque([(start, 0)])
    visited.add(start)
    max_depth = 0
    
    while queue:
        node, depth = queue.popleft()
        max_depth = max(max_depth, depth)
        
        for neighbor in graph[node]:
            if neighbor not in visited:
                visited.add(neighbor)
                queue.append((neighbor, depth + 1))
    
    return max_depth

# Read the input from stdin
def read_input():
    input = sys.stdin.read().splitlines()
    n = int(input[0])  # number of nodes
    graph = defaultdict(list)
    
    for i in range(n):
        line = list(map(int, input[i + 1].split()))
        graph[i] = line  # adjacency list for each node
    
    return graph

# Main function
def main():
    graph = read_input()
    
    visited = set()
    heights = []

    for node in graph:
        if node not in visited:
            height = bfs(graph, node, visited)
            heights.append(height)

    # Print the heights of each tree in the BFS forest
    for height in heights:
    	if height>0:
        	print(height, end=" ")

# Entry point
main()
