시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
4 초 512 MB 2 1 1 100.000%

문제

Professor Anna van Lier is preparing to give a lecture on balanced binary search trees. Recall that these are binary trees with two properties:

  • Balanced tree: For every node, the height of its left subtree and the height of its right subtree differ by at most 1. For instance in Figure B.1, the left and right subtrees of node 7 have heights 2 and 1, respectively. If a node does not have a left (or right) subtree then that subtree is considered to have height 0.
  • Search tree: Each node has a value. The value of a node is greater than all the values in the left subtree of the node, and smaller than all the values in the right subtree of the node. For instance in Figure B.1, the left subtree of node 7 contains the values 4, 5 and 6 which are all smaller than 7.

Anna got a picture of such a tree from a colleague. This tree has n nodes with the values 1 to n. However, it turns out to be too big to fit on her slides so she would like to make it smaller. In particular, she would like to erase some nodes from the tree such that it has exactly k remaining nodes. Whenever she erases a node, she also erases the subtrees of that node. Of course, the resulting tree must still be a balanced binary search tree.

For pedagogical purposes, Anna would like the node values in her final tree to be small. Therefore, she wants the list of the k remaining node values to be the lexicographically smallest possible. For example she would prefer a tree containing values 2, 5, 9 over a tree containing values 2, 6, 7.

As Anna is far too busy doing more important things, the task of finding which nodes to erase falls upon one of her teaching assistants, i.e., you.

Figure B.1: Illustration of Sample Input 2 and its solution.

입력

The input consists of:

  • One line with two integers n and k (2 ≤ n ≤ 5 · 105, 1 ≤ k ≤ n − 1), the number of nodes in the tree and the number of nodes to keep.
  • n lines, the ith of which contains an integer pi (1 ≤ pi ≤ n or pi = −1), the parent of the node with value i or −1 if the node with value i is the root.

It is guaranteed that the given tree is a balanced binary search tree.

출력

Output a single line with a binary string of length n. The ith character should be ‘1’ if the node with value i should be kept, and ‘0’ if it should be erased.

예제 입력 1

3 1
2
-1
2

예제 출력 1

010

예제 입력 2

8 5
3
1
-1
5
7
5
3
7

예제 출력 2

11101010