当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

5822:color

题目描述
You are given a directed graph, which is constructed as follows:
+ Pick an connected undirected graph with exactly n vertices and n edges. The vertices are numbered 1 through n.
+ Convert each undirected edge into a directed edge, satisfying each vertice's outdegree equals 1.

Also you're given m different colors to color the vertices. Your task is to calculate the number of different colored graphs that can be made.

Two colored graphs A and B are considered the same if and only if there exists a mapping P satisfying the following constraints:

+ Vertice u in graph A has the same color as vertice P(u) in graph B.
+ For any two different vertices u and v in graph A, P(u) and P(v) are different vertices in graph B.
+ For any directed edge u -> v in graph A, there exists a corresponding directed edge P(u) -> P(v) in graph B.

Print the answer module 10^9 + 7.
输入解释
The first line contains a number T(1 <= T <= 10), denoting the number of testcases.

For each testcase, the first line contains two space-seperated integers n and m(3 <= n <= 10^5, 1 <= m <= 10^9), representing the number of vertices in the graph and the number of colors you have.

Then, n lines follow. The i-th of them contains an integer f_i, denoting a directed edge from vertice i to vertice f_i in the given graph.(1 <= f_i <= n, f_i != i)
输出解释
For each testcase, print a line containing the answer.
输入样例
1
6 3
2
3
4
1
1
3
输出样例
378
来自杭电HDUOJ的附加信息
Author 学军中学
Recommend wange2014

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-5822

最后修改于 2020-10-25T23:25:56+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
2000/1000MS(Java/Others) 131072/131072K(Java/Others)