Question
Turn-Budget Leaves
Every left edge of a binary tree is an L move and every right edge is an R move. A turn occurs whenever two consecutive moves differ. The first move never counts as a turn. Count root-to-leaf paths using at most
Input
First line: KaTeX can only parse string typed expression.
For nodes 1..n, one line gives left child and right child; 0 means missing. Node 1 is the root.
Output
Print the number of valid leaves.
Example
Input:
7 1
2 3
4 5
6 7
0 0
0 0
0 0
0 0Output:4