import java.util.*;
public class Main {
static int[] start = new int[100001];
static int[] end = new int[100001];
static Vector<Integer> dfs_order
= new Vector<Integer>();
static Vector<Vector<Integer> > adj
= new Vector<Vector<Integer> >();
static boolean[] visited = new boolean[100001];
static int dfs(int a, int b)
{
visited[a] = true;
b += 1;
start[a] = b;
dfs_order.add(a);
for (int it = 0; it < adj.get(a).size(); it++) {
if (!visited[adj.get(a).get(it)])
b = dfs(adj.get(a).get(it), b);
}
endd[a] = b;
return b;
}
static void Print(int n)
{
for (int i = 0; i < n; i++) {
if (start[i] != endd[i]) {
System.out.print("subtree of node " + i
+ " is ");
for (int j = start[i] + 1; j < endd[i] + 1;
j++) {
System.out.print(dfs_order.get(j - 1)
+ " ");
}
System.out.println();
}
}
}
public static void main(String[] args)
{
int n = 10, c = 0;
for (int i = 0; i < 100001; i++) {
adj.add(new Vector<Integer>());
}
adj.get(0).add(1);
adj.get(0).add(2);
adj.get(0).add(3);
adj.get(1).add(4);
adj.get(1).add(5);
adj.get(4).add(7);
adj.get(4).add(8);
adj.get(2).add(6);
adj.get(6).add(9);
dfs(0, c);
Print(n);
}
}