using System.Collections.Generic;
public static void Main()
int N = int.Parse(Console.ReadLine());
Dictionary<int, int[]> relations = new Dictionary<int, int[]>();
for(int i = 0; i < N; i++)
string[] s = Console.ReadLine().Split(' ');
if(maxChildren < s.Length - 1)
maxChildren = s.Length - 1;
int[] children = new int[s.Length - 1];
for(int j = 0; j < s.Length - 1; j++)
children[j] = int.Parse(s[j]) - 1;
relations.Add(i, children);
Dictionary<int,int> weights = new Dictionary<int,int>();
for(int i = 0; i < N; i++)
int currentChildCount = 0;
while(currentChildCount <= maxChildren)
for(int i = 0; i < N; i++)
if(relations[i].Length == currentChildCount)
foreach(int w in relations[i])
childWeights += weights[w];
weights[i] = currentChildCount + childWeights;
foreach(KeyValuePair<int,int> kvp in weights.OrderByDescending(a => a.Value))
Console.Write((kvp.Key + 1) + " ");