Of Cayley C A y L E defined y the formula is such that, for n different nodes, can be composed of unrooted trees (the original is not the tree connected graph or is sign node) number of species are n ^ (n -2) species. (Here, let Hello everyone understand that it is written in a tree without roots, in fact, should be the same concept)
So our initial problem is solved, the next step is to solve the transition between unrooted trees and rooted tree.
But it is difficult to convert? Converted into a rooted tree with a root node of the n- n-case of unrooted trees, i.e. n-^ (n--2) * n-, simplification is n-^ (n--. 1) . The answer is this stuff up.
Because this question, the n- large, so we used it to quickly power.
#include <iostream> #include <cstdio> #include <fstream> #include <algorithm> #include <cmath> #include <deque> #include <vector> #include <queue> #include <string> #include <cstring> #include <map> #include <stack> #include <set> #define LL long long #define ULL unsigned long long #define rep(i,j,k) for(int i=j;i<=k;i++) #define dep(i,j,k) for(int i=k;i>=j;i--) #define INF 0x3f3f3f3f #define mem(i,j) memset(i,j,sizeof(i)) #define make(i,j) make_pair(i,j) #define pb push_back using namespace std; const int mod = 1e9 + 9; LL ksm(LL a, LL b) { LL ans = 1; while(b) { if(b & 1) ans = ans * a % mod; a = a * a % mod; b >>= 1; } return years; } int main() { int n, t; scanf("%d", &t); while(t--) { scanf("%d", &n); cout << ksm(1LL * n, 1LL * ( n - 1)) <<endl; } return 0; }
Reproduced in: https: //www.cnblogs.com/Willems/p/11016727.html