Colored Graphs

아직 제출이 없습니다시간 제한1초메모리 제한512 MB

문제

You are given a directed graph which is constructed as follows:

  • Pick a connected undirected graph with exactly nn vertices and nn edges. The vertices are numbered 11 through nn.
  • Convert each undirected edge into a directed edge in such a way that each vertex has outdegree 11.

Additionally, you are given mm different colors to color the vertices. Your task is to calculate the number of different colored graphs that can be made.

Two colored graphs AA and BB are considered the same if and only if there exists a mapping PP between their sets of vertices which satisfies the following constraints:

  • Vertex uu in graph AA has the same color as vertex P(u)P (u) in graph BB
  • For any two different vertices uu and vv in graph AA, P(u)P (u) and P(v)P (v) are different vertices in graph BB.
  • For any directed edge uvu \to v in graph AA, there exists a corresponding directed edge P(u)P(v)P (u) \to P (v) in graph BB.

Print the answer modulo 109+710^9 + 7.

입력

The first line of the input contains two space-seperated integers nn and mm (3n1053 \le n \le 10^5, 1m1091 \le m \le 10^9), representing the number of vertices in the graph and the number of colors you have.

Then, nn lines follow. The ii-th of them contains an integer f_if\_i (1f_in1 \le f\_i \le n, f_iif\_i \ne i), denoting a directed edge from vertex ii to vertex f_if\_i in the given graph.

출력

Print a single line containing the answer.