Logo
(追記) (追記ここまで)

19387번 - Counting Orders 다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2 초 512 MB522100.000%

문제

You are given a rooted tree on $n$ vertices numbered from 1ドル$ to $n$. The root of the tree is vertex 1ドル,ドル and for each vertex $i$ ($i \geq 2$), its parent is vertex $p_i$.

Consider a permutation $q_i$ (1ドル \le i \le n$). We will call this permutation proper if, for any vertex $v,ドル all its descendants are located to the right of the position of $v$ in permutation $q$.

You are asked to find the number of proper permutations $q_i$ such that $q_k = v,ドル taken modulo 10ドル^9 + 7$.

입력

The first line of the input contains a single integer $n$ (1ドル \leq n \leq 5000$), the number of vertices in the tree.

The second line contains $n-1$ integers $p_2, p_3, \ldots, p_n$ (1ドル \leq p_i < i$), the parents of all vertices in the tree except the root. In particular, when $n = 1,ドル the second line is present but empty.

The last line contains two integers $v$ and $k$ (1ドル \le v, k \le n$).

출력

Output one integer: the remainder of the number of proper permutations $q_i$ with $q_k = v$ modulo 10ドル^9 + 7$.

제한

예제 입력 1

6
1 1 1 2 3
2 3

예제 출력 1

9

힌트

The valid proper permutations for the sample case are:

1ドル 3 2 4 5 6,ドル 1ドル 3 2 4 6 5,ドル 1ドル 3 2 5 4 6,ドル 1ドル 3 2 5 6 4,ドル 1ドル 3 2 6 4 5,ドル 1ドル 3 2 6 5 4,ドル 1ドル 4 2 3 5 6,ドル 1ドル 4 2 3 6 5,ドル 1ドル 4 2 5 3 6$.

출처

Camp > Petrozavodsk Programming Camp > Winter 2017 > Day 4: Yandex Cup 2017 F번

(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /