# BZOJ 1002：[FJOI2007] 轮状病毒 (基尔霍夫矩阵生成树定理)

轮状病毒有很多变种，所有轮状病毒的变种都是从一个轮状基产生的。一个N轮状基由圆环上N个不同的基原子

N轮状病毒的产生规律是在一个N轮状基中删去若干条边，使得各原子之间有唯一的信息通道，例如共有16个不

现给定n(N<=100)，编程计算有多少个不同的n轮状病毒
Input
第一行有1个正整数n

Output
计算出的不同的n轮状病毒数输出

Sample Input
3
Sample Output
16
HINT
Source

import java.util.*;
import java.math.*;
public class Main{
static int maxn = 105;
static BigInteger tot = BigInteger.ONE;
static BigInteger a[][] = new BigInteger[maxn][maxn];
static int n;
static BigInteger lcm(BigInteger x,BigInteger y){
return x.divide(x.gcd(y)).multiply(y);
}
static void debug(){
for (int i = 0; i < n; i++){
for (int j = 0; j < n; j++)
System.out.print(a[i][j] + " ");
System.out.println();
}
}
static void Gauss(int equ,int  var){
int i,j,k;
int max_r;
int col;
BigInteger ta,tb;
BigInteger LCM;
int temp;
col = 0;
for (k = 0; k < equ && col < var; k++ ,col ++){
max_r = k;
for (i = k + 1; i < equ; i++){
if (a[i][col].abs().compareTo(a[max_r][col].abs()) > 0) max_r = i;
}
if (max_r != k){
for (j = k; j < var + 1; j++)
{
BigInteger t;
t = a[k][j];
a[k][j] = a[max_r][j];
a[max_r][j] = t;
}
}
if (a[k][col].equals(BigInteger.ZERO))
{
k--;
continue;
}
for (i = k + 1; i < equ; i++){
if (!a[i][col].equals(BigInteger.ZERO))
{
LCM = lcm(a[i][col].abs(),a[k][col].abs());
ta = LCM.divide(a[i][col].abs());
tb = LCM.divide(a[k][col].abs());
tot  = tot.multiply(ta);
if (a[i][col].multiply(a[k][col]).compareTo(BigInteger.ZERO) < 0) tb = tb.multiply(BigInteger.valueOf(-1));
for (j = col; j < var + 1; j++){
a[i][j] = a[i][j].multiply(ta).subtract(a[k][j].multiply(tb));
}
}
}
}
}

public static void main(String agrs[]){
Scanner cin = new Scanner(System.in);
n = cin.nextInt();
for (int i = 0; i < n + 1; i++){
for (int j = 0; j < n + 1; j++)
a[i][j] = BigInteger.ZERO;
}
for (int i = 0; i < n; i++){
a[i][i + 1] = BigInteger.valueOf(-1);
a[i + 1][i] = BigInteger.valueOf(-1);
a[i][i] = BigInteger.valueOf(3);
}
a[n - 1][0] = BigInteger.valueOf(-1);
a[0][n - 1] = BigInteger.valueOf(-1);
Gauss(n,n);
BigInteger ans = BigInteger.ONE;
for (int i = 0; i < n; i++) ans = ans.multiply(a[i][i]);
if (n == 2) System.out.println("5");
else System.out.println(ans.divide(tot).abs());

}

}