将问题抽象出来后,就是求完全图最小生成树的方法数,n! * n^(n-2),再利用同余定理求得结果
// Problem#: 1141
// Submission#: 1857876
// The source code is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License
// URI: http://creativecommons.org/licenses/by-nc-sa/3.0/
// All Copyright reserved by Informatic Lab of Sun Yat-sen University
#include <stdio.h>
int main()
{
int n;
scanf ("%d",&n);
int res = 1;
for (int i = 1; i < n; i ++) res = res * i % 10007;
for (int i = 0; i < n - 2; i++) res = res % 10007 * n % 10007;
printf ("%d\n",res);
return 0;
}