#K73017. Find Leaf Nodes in a Tree
Find Leaf Nodes in a Tree
Find Leaf Nodes in a Tree
You are given a tree represented as a series of node descriptions. Each node is described by a list of integers where the first integer represents the node's label, the second integer represents the number of children (denoted by K), and if K > 0 then the next K integers represent the node's children labels.
Your task is to identify all leaf nodes (nodes with no children) and output their labels in increasing order.
In mathematical form, a node is a leaf if and only if $$K=0$$.
inputFormat
The input is provided via stdin in the following format:
- The first line contains a single integer
N
representing the number of nodes. - Each of the following
N
lines describes a node with space-separated integers. The first integer is the node label, the second integer isK
(the number of children), followed byK
integers representing the children labels (if any).
outputFormat
Output the labels of the leaf nodes in increasing order. The output should be printed to stdout as a single line of space-separated integers.
## sample5
1 2 2 3
2 0
3 2 4 5
4 0
5 0
2 4 5