### Description

In some countries building highways takes a lot of time... Maybe that's because there are many possiblities to construct a network of highways and engineers can't make up their minds which one to choose. Suppose we have a list of cities that can be connected directly. Your task is to count how many ways there are to build such a network that between every two cities there exists exactly one path. Two networks differ if there are two cities that are connected directly in the first case and aren't in the second case. At most one highway connects two cities. No highway connects a city to itself. Highways are two-way.

### Input

The input begins with the integer t, the number of test cases (equal to about 1000). Then t test cases follow. The first line of each test case contains two integers, the number of cities (1<=n<=12) and the number of direct connections between them. Each next line contains two integers a and b, which are numbers of cities that can be connected. Cities are numbered from 1 to n. Consecutive test cases are separated with one blank line.

### Output

The number of ways to build the network, for every test case in a separate line. Assume that when there is only one city, the answer should be 1. The answer will fit in a signed 64-bit integer.

4
4 5
3 4
4 2
2 3
1 2
1 3
2 1
2 1
1 0
3 3
1 2
2 3
3 1

8
1
1
3

matrix-tree定理简述:

### Code

#include<bits/stdc++.h>
#define maxn 15
#define eps 1e-6
// #define DEBUG
using namespace std;
int cnt,n,m;
double a[maxn][maxn];

inline int dcmp(double x)
{
if(abs(x)<eps) return 0;
else return x>0?1:-1;
}

{
char ch;
do
ch=getchar();
while((ch<'0'||ch>'9')&&ch!='-');
if(ch=='-') sign=-1,ch=getchar();
while(ch>='0'&&ch<='9')
{
ch=getchar();
}
}

void init()
{
memset(a,0,sizeof(a));
if (n == 1) return;
for(int i=1;i<=m;++i)
{
a[u][v]=a[v][u]=-1;
a[u][u]++,a[v][v]++;
}
#ifdef DEBUG
for(int i=1;i<=n;++i){
for(int j=1;j<=n;++j)
cout<<a[i][j]<<" ";
cout<<endl;}
#endif
n--;
}

void gauss()
{
if(n==1)
{
printf("1\n");
return;
}
for(int i=1;i<=n;++i)
{
if(!dcmp(a[i][i]))
{
int k=i;
while(!dcmp(a[k][k])) k++;
swap(a[k],a[i]);
}
for(int j=i+1;j<=n;++j)
{
for(int k=i+1;k<=n;++k)
a[j][k]-=a[i][k]*(a[j][i]/a[i][i]);
a[j][i]=0;
}
}
double ans=1;
for(int i=1;i<=n;++i) ans*=a[i][i];
printf("%.0lf\n",ans);
}

int main()
{
while(cnt--)
{
init();
gauss();
}
return 0;
}

/*
Sample input:
4
4 5
3 4
4 2
2 3
1 2
1 3

2 1
2 1

1 0

3 3
1 2
2 3
3 1

Sample output:
8
1
1
3
*/


Responses