시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
3 초 512 MB 1 0 0 0.000%

## 문제

Did you now that most standard libraries use red-black tree to implement "set" data structure? In this problem you have to find the number of ways to color the vertices of the given binary tree so that it became red-black. Print the answer modulo 109 + 7.

Consider a binary tree. If the vertex has less than two children, add fake vertices to the potential places of the missing children. The tree is called a red-black tree if the following constraints are satisfied:

1. Each vertex is colored one of the two colors: red or black.
2. The root of the tree and added fake vertices are colored black.
3. The parent of a red vertex is black.
4. All paths the root to fake leafs contain the same number of black vertices.

Note that the parent of a black vertex can be black itself.

Two ways to color the tree are different if there is a vertex that has different colors.

The picture shows two ways to color the tree from the second test case. ## 입력

The first line contains one integer n — the number of vertices in a tree (1 ≤ n ≤ 500 000).

The following n lines describe a tree. The i-th of these lines contains two integers li and ri — the indices of the left and the right child of the i-th vertex, or 0 if the corresponding child is missing (li = 0 or i < li ≤ n; ri = 0 or i < ri ≤ n). The root of the tree has number 1. Input describes the correct tree.

## 출력

Output one integer — the number of ways to color the given tree so that it was a correct red-black tree. The answer must be printed modulo 109 + 7.

## 예제 입력 1

3
2 3
0 0
0 0


## 예제 출력 1

2


## 예제 입력 2

6
2 4
3 0
0 0
5 6
0 0
0 0


## 예제 출력 2

2
{"ft_lang_label":"__label__en","ft_lang_prob":0.8900975,"math_prob":0.90068245,"size":1359,"snap":"2021-04-2021-17","text_gpt3_token_len":380,"char_repetition_ratio":0.1298893,"word_repetition_ratio":0.04225352,"special_character_ratio":0.29212657,"punctuation_ratio":0.06622516,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9775653,"pos_list":[0,1,2],"im_url_duplicate_count":[null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-27T07:12:51Z\",\"WARC-Record-ID\":\"<urn:uuid:027fb9c9-7039-4794-9ab5-5c450989276c>\",\"Content-Length\":\"27297\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f9baa32d-a78b-4e1a-aed3-489d280ba501>\",\"WARC-Concurrent-To\":\"<urn:uuid:ece48831-88e0-4a1c-83aa-9589351043e8>\",\"WARC-IP-Address\":\"52.194.157.171\",\"WARC-Target-URI\":\"https://www.acmicpc.net/problem/16263\",\"WARC-Payload-Digest\":\"sha1:XFFI4KQMFDVHSM2UUHLF245ENPPXANSK\",\"WARC-Block-Digest\":\"sha1:DYSGDG6H5U5R2BQ7FVSVJ24EZD4JGFUE\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610704821253.82_warc_CC-MAIN-20210127055122-20210127085122-00427.warc.gz\"}"}