HIGH - Highways

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.

Example

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

生成树计数

1、构造 基尔霍夫矩阵(又叫拉普拉斯矩阵)

n阶矩阵

若u、v之间有边相连 C[u][v]=C[v][u]=-1

矩阵对角线为点的度数

2、求n-1阶主子式 的行列式的绝对值

去掉第一行第一列

 初等变换消成上三角矩阵

对角线乘积为行列式

#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long LL;
int n;
LL C[][],tmp[];
int main()
{
int T,m,u,v;
LL t,ans;
scanf("%d",&T);
while(T--)
{
memset(C,,sizeof(C));
scanf("%d%d",&n,&m);
while(m--)
{
scanf("%d%d",&u,&v);
u--; v--;
C[u][v]=-; C[v][u]=-;
C[u][u]++; C[v][v]++;
}
ans=;
for(int i=;i<n;i++)
{
for(int j=i+;j<n;j++)
while(C[j][i])
{
t=C[i][i]/C[j][i];
for(int k=i;k<n;k++) C[i][k]-=C[j][k]*t;
for(int k=i;k<n;k++) swap(C[i][k],C[j][k]);
ans=-ans;
}
ans*=C[i][i];
if(!ans) break;
}
if(ans<) ans=-ans;
printf("%lld\n",ans);
}
}

最新文章

  1. Linux TOP命令 按内存占用排序和按CPU占用排序
  2. Jmeter 简单用法
  3. 一个无聊的python + opencv 示例
  4. Get a List of Keys From a Dictionary in Both Python 2 and Python 3
  5. Android 虚拟机安装SD卡
  6. js判断访问者是否来自移动端代码
  7. Hibernat之关系的处理一对多/多对一
  8. 2--OC -- 类的创建与实例化
  9. Ultra-QuickSort(树状数组求逆序对数)
  10. from语法导入
  11. cadence钻孔文件及光绘文件的生成
  12. JSONObject.parseObject
  13. [转]ORACLE 11G 导出报错(EXP-00003)未找到段 (0,0) 的存储定义
  14. Linux安装Apache常见报错(一)
  15. Junit的Assert用法
  16. [SDOI2016]数字配对
  17. Thymeleaf 条件语句
  18. Redis 配置和使用
  19. word中在空白处加下划线不显示解决
  20. day12-迭代器

热门文章

  1. logstash+elasticsearch 错误摘记
  2. Mishka and Contest(模拟水题)
  3. Thunder团队第一周 - Scrum会议7
  4. P4语法(1)基础数据类型和Header
  5. 3dContactPointAnnotationTool开发日志(二三)
  6. 封装字符串的Format操作
  7. [OS] 信号量(Semaphore)
  8. vdbench-自动化测试脚本
  9. hdu 1142 A Walk Through the Forest (最短路径)
  10. Codeforces Gym 101142 C. CodeCoder vs TopForces(思维+图论)