#1121
Unrated
PALETA
시간 제한
1s
메모리 제한
32MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Author: Domagoj Ćevid

Little Mirko spends his free time painting. For this hobby, he likes to use brushes and a pallet containing K colors overall. His friend Slavko decided to use Mirko's talent and gave him his new coloring book for Mirko to color. The coloring book contains N images numbered 1, 2, ..., N.

Mirko has decided to paint each image in exactly one color of the possible K colors from his pallet. However, he really likes colorful things. He chose N numbers fi and decided to paint the image numbered i differently than the images numbered fi, except when fi = i. If fi = i, that means he can paint the image numbered fi whichever color he likes, as long as all other conditions have been met.

Mirko wants to know the number of possible ways to color Slavko's coloring book and he desperately needs your help! Calculate the number of possible ways to color the book. Given the fact that the output can be very large, print the answer modulo 1 000 000 007.

입력

The first line of input contains positive integers N, K (1 ≤ N, K ≤ 1 000 000). Following line contains N numbers fi (1 ≤ fi ≤ N), the number stated in the text.

출력

The first and only line must contain the number of possible ways to color Slavko's book.

예제 입력 1

2 3
2 1

예제 출력 1

6

예제 입력 2

3 4
2 3 1

예제 출력 2

24

예제 입력 3

3 4
2 1 1

예제 출력 3

36
코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.