포럼
문제 ICPC00258

K. King's Colors

스페셜 저지 — 출력을 사용자 정의 프로그램으로 검사하므로 여러 정답이 인정될 수 있습니다.
설명

Far, far away, there is the mystical Kingdom of Trees (more formally, "Royal Commonwealth of Connected Undirected Simple Acyclic Graphs"). The King there is very sad because his kingdom is not accepted as a sovereign state in the United Nations. In order to become a member, he needs to make a flag the UN can put on their website.

The flag will of course consist of the King's favorite tree, which contains \(n\) nodes. The King would be happy to just have the tree colored in black and white, but for the sake of his wife the Queen, he decided that the tree will contain all the favorite colors of their \(k\) children (they all have distinct favorite colors). Clearly, no two neighboring nodes can have the same color, but otherwise any coloring of the tree using exactly the \(k\) colors would make a feasible flag candidate.

How many different flags are possible?

제약
입력 형식

The first line contains two integers \(n\) and \(k\) (\(2 \le k \le n \le 2\,500\)), where \(n\) is the number of nodes in the King's favorite tree and \(k\) is the number of children. Then follow \(n-1\) lines describing the edges in the tree; the \(i\)'th of these lines contains a non-negative integer \(p_i < i\), meaning that node \(p_i\) is the parent of \(i\).

The nodes are numbered from \(0\) to \(n-1\) and the tree is rooted at node \(0\). Note that the embedding of the tree on the flag is already fixed, the only thing that remains is to assign colors.

출력 형식

Output the number of different possible color assignments. The number can be quite big, so the King has requested to know the answer modulo \(1\,000\,000\,007\).

예제 1
입력
4 3
0
1
1
출력
18
예제 2
입력
6 4
0
1
1
3
4
출력
600
문제 정보

생성자가 기록되지 않았습니다.

출처 ICPC NCPC 2018

평가 및 의견

K. King's Colors

개요
출제자 난이도 Unrated 레이팅 미적용 의견 0 / 1 공개 집계 (커뮤니티 난이도, 주요 주제, 품질)는 의견이 충분히 모이면 공개됩니다.

Log in to rate problems.

개별 의견

아직 의견이 없습니다. 자격이 된다면 위 양식에서 가장 먼저 평가해 보세요.

풀이 제출

K. King's Colors

게스트로 둘러보고 있습니다. 로그인하면 풀이를 제출하고 진행 상황을 확인할 수 있습니다. 로그인하고 제출하기
공개
C++20 Tab 들여쓰기 · Ctrl+/ 주석 토글 · Enter 자동 들여쓰기
1 1 1 0 공백: 4 · UTF-8