Cow the Cow has a tree of size $$$n$$$ rooted at node $$$1$$$. However, Cow the Nerd thinks that Cow the Cow's tree is boring, so he has assigned you the task of painting it.
Specifically, let your current position be $$$u$$$. In a move, you will do one of the following:
For every node $$$u$$$ from $$$1$$$ to $$$n$$$, find out if it is possible to paint all nodes of the tree and escape successfully if you start from node $$$u$$$.
$$$^\dagger$$$A leaf of a rooted tree is a node that is not the root and has no children.
The first line contains exactly one integer $$$n$$$ $$$(2 \le n \le 2 \cdot 10^5)$$$.
The second line contains $$$n - 1$$$ integers $$$p_2, p_3, ..., p_n$$$, where $$$p_i$$$ is the parent of the $$$i$$$-$$$th$$$ node.
It is guaranteed that the input provides a valid tree.
Output a binary string $$$s$$$ of size $$$n$$$, where $$$s_i = 1$$$ if you can win starting from node $$$i$$$, and $$$s_i = 0$$$ otherwise.
51 1 1 1
11111
21
10
61 1 2 3 4
111000
In the first example, no matter which node you start from, there's at least one possible winning sequence of moves.
In the second example, if you start from node $$$2$$$, there's only one possible sequence of moves: paint node $$$2$$$, and since it is a leaf, move to the only unpainted node, $$$1$$$. Node $$$1$$$ is not a leaf, and all of its children have been painted; therefore, you lose.