题目描述

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.

输入输出格式

输入格式:

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.

输出格式:

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.

输入输出样例

输入样例#1:

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

输出样例#1:

8

1

1

3

先用高斯消元转化为上三角,后求对角线之积算出行列式绝对值

code:

//Menteur_Hxy
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
#define ll long long ll rd() {
ll x=0,fla=1; char c=' ';
while(c<'0' || c>'9') {c=getchar();if(c=='-') fla=-fla;}
while(c>='0' && c<='9') x=x*10+c-'0',c=getchar();
return x*fla;
} const double eps=1e-12;
int T,n,m;
double a[3010][3010]; void gauss() {
for(int i=1;i<=n;i++) {
int mx=i;
for(int j=i+1;j<=n;j++) mx=(a[mx][i]-a[j][i]<-eps)?i:mx;
if(mx!=i) swap(a[i],a[mx]);
if(!a[i][i]) {printf("0\n");return ;}
for(int j=i+1;j<=n;j++) {
double t=a[j][i]/a[i][i];
for(int k=i;k<=n+1;k++)
a[j][k]-=t*a[i][k];
}
}
double ans=1;
for(int i=1;i<=n;i++) ans=ans*a[i][i];
printf("%.0f\n",fabs(ans));
} int main() {
T=rd();
while(T--) {
memset(a,0,sizeof a);
n=rd()-1,m=rd();
for(int i=1;i<=m;i++) {
int u=rd(),v=rd();
a[u][u]++,a[v][v]++;
a[u][v]--,a[v][u]--;
}
gauss();
}
return 0;
}

最新文章

  1. 我的MYSQL学习心得(七) 查询
  2. 解析Exception和C#处理Exception的常用方法总结
  3. JAVA中读取xls数据方法介绍
  4. tunnel.p4
  5. laravel 5.0 artisan 命令列表(中文简体)
  6. Java API —— HashMap类 &amp; LinkedHashMap类
  7. 【HDOJ】1003 Max Sum
  8. cakephp 的事件系统(Getting to grips with CakePHP’s events system), 基于观察者模式
  9. 深入学习rollup来进行打包
  10. Java学习笔记19---内部类之简介成员内部类、局部内部类及匿名内部类
  11. Lucene入门案例一
  12. Spring AOP中的JDK和CGLib动态代理哪个效率更高?
  13. 【web】服务器推送的实现方式(转)
  14. nginx默认80端口被System占用,造成nginx启动报错的解决方案
  15. Ubuntu18.04终端设置为zsh后的问题记录
  16. 删除maven仓库中的LastUpdated文件
  17. AJAX----注:借鉴
  18. PHP输出缓存ob系列函数详解
  19. Spring boot FastJson
  20. Linux若干源码编译

热门文章

  1. codevs——T1220 数字三角形
  2. 非form表单提交的数据就要用@requestbody注解获取http传过来的值,尤其json
  3. HDU 5184
  4. [Javascript] Understand common misconceptions about ES6&#39;s const keyword
  5. [Wikioi 1226]倒水问题
  6. ArcGIS教程:加权总和
  7. 64bit Centos6.4搭建hadoop-2.5.1
  8. java 10000的阶乘
  9. 使用spring mvc或者resteasy构建restful服务
  10. ClassLoader.getResourceAsStream(name);获取配置文件的方法