题目描述

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;
}

【SPOJ 104】HIGH - Highways (高斯消元)的更多相关文章

  1. SPOJ HIGH Highways ——Matrix-Tree定理 高斯消元

    [题目分析] Matrix-Tree定理+高斯消元 求矩阵行列式的值,就可以得到生成树的个数. 至于证明,可以去看Vflea King(炸树狂魔)的博客 [代码] #include <cmath ...

  2. SPOJ HIGH(生成树计数,高斯消元求行列式)

    HIGH - Highways no tags  In some countries building highways takes a lot of time... Maybe that's bec ...

  3. [spoj104][Highways] (生成树计数+矩阵树定理+高斯消元)

    In some countries building highways takes a lot of time... Maybe that's because there are many possi ...

  4. 【BZOJ-3143】游走 高斯消元 + 概率期望

    3143: [Hnoi2013]游走 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 2264  Solved: 987[Submit][Status] ...

  5. 【BZOJ-3270】博物馆 高斯消元 + 概率期望

    3270: 博物馆 Time Limit: 30 Sec  Memory Limit: 128 MBSubmit: 292  Solved: 158[Submit][Status][Discuss] ...

  6. *POJ 1222 高斯消元

    EXTENDED LIGHTS OUT Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9612   Accepted: 62 ...

  7. [bzoj1013][JSOI2008][球形空间产生器sphere] (高斯消元)

    Description 有一个球形空间产生器能够在n维空间中产生一个坚硬的球体.现在,你被困在了这个n维球体中,你只知道球 面上n+1个点的坐标,你需要以最快的速度确定这个n维球体的球心坐标,以便于摧 ...

  8. hihoCoder 1196 高斯消元·二

    Description 一个黑白网格,点一次会改变这个以及与其连通的其他方格的颜色,求最少点击次数使得所有全部变成黑色. Sol 高斯消元解异或方程组. 先建立一个方程组. \(x_i\) 表示这个点 ...

  9. BZOJ 2844 albus就是要第一个出场 ——高斯消元 线性基

    [题目分析] 高斯消元求线性基. 题目本身不难,但是两种维护线性基的方法引起了我的思考. void gauss(){ k=n; F(i,1,n){ F(j,i+1,n) if (a[j]>a[i ...

随机推荐

  1. Sublime Text 3常用插件—Emmet

    原文链接:http://www.cnblogs.com/easy-blue/p/6617852.html 摘要: 安装请看上一篇Sublime Text—安装,和sublime自带快捷键一起用,写ht ...

  2. maven 自动部署到tomcat

    使用maven的自动部署功能可以很方便的将maven工程自动部署到远程tomcat服务器,减少部署时间,方便快捷. 一.配置tomcat manager 1.编辑tomcat目录下,conf/tomc ...

  3. luogu1072 Hankson的趣味题

    题目大意 给出数a0, a1, b0, b1,求满足gcd(a0, x)=a1, lcm(b0, x)=b1的x的个数 解法一 枚举b1的因数,看看是否满足上述条件. 怎样枚举因数 试除法.对于1~s ...

  4. c26---文件包含include

    // // main.c // 文件包含 #include <stdio.h> // 函数可以重复声明, 但不能重复定义 void test(); void test(); void te ...

  5. adbd cannot run as root in production builds的解决方法

    部分手机root后,使用adb root会出现这个提示. 原因是root不彻底. adb shell之后进入到$界面,su一下才进入到#. 这个之后可以使用root功能了. 注意到,这个时候exit的 ...

  6. poj 2031--Building a Space Station(prim)

    Building a Space Station Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 6064   Accepte ...

  7. c#为程序添加全局热键的方法

    在程序失去焦点或者在后台运行时,可以通过使用全局热键的方式,进行一些快捷的操作,如QQ默认操作中ctrl+alt+A调出截图功能. 在Windows中实现热键功能需要使用win32的Api函数Regi ...

  8. c# 获取本周开始时间与结束时间

    public static DateTime WeekStartTime { get { DateTime dt = DateTime.Now; * ();//取本周一 ) //如果今天是周日,则开始 ...

  9. AIX的系统备份

    AIX克隆盘即AIX的rootvg的备用替换磁盘,用于保留AIX的原始状态,它可作为软件的升级后出现问题快速回退到原系统的备份手段,也可用于测试两个不同版本的AIX系统.系统可保留两块引导磁盘,而且都 ...

  10. ABP框架应用汇总

        相信很多人可能听过或没听过ABP这个框架,在我接触此框架时也是在现在所在的公司开始接触的,我们用此开源框架作为我们项目的架构,我们正好做的是Saas云服务多租户管理系统开发,并且经过了一年多高 ...