题目描述

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. BEGINNING SHAREPOINT&#174; 2013 DEVELOPMENT 第12章节--SP 2013中远程Event Receivers 总结

    BEGINNING SHAREPOINT® 2013 DEVELOPMENT 第12章节--SP 2013中远程Event Receivers  总结         本章节向你介绍了SP平台上eve ...

  2. HDU 2027 汉字统计

    汉字统计 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...

  3. Cocos2d-x3.3beta0创建动画的3种方式

    1.单独载入精灵对象 渲染效率低,浪费资源,不推荐用该方法.代码例如以下:注:代码仅仅需贴到HelloWorldScene.cpp中就可以. //First,单独渲染每个精灵帧 auto sprite ...

  4. JDBC中向数据库录入汉字产生乱码的解决办法

    在近期的课程设计中遇到在eclipse中向数据库中录入数据,产生的汉字乱码现象,在这里提供一条解决的方法: 只需连接地址URL中数据库名后面添加“?characterEncoding=utf-8”即可 ...

  5. hdoj--1258--Sum It Up(dfs)

    Sum It Up Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total ...

  6. 杂项-SpringEureka:笔记-1

    ylbtech-杂项-SpringEureka:笔记-1 1.返回顶部 1. THE SELF PRESERVATION MODE IS TURNED OFF.THIS MAY NOT PROTECT ...

  7. 使用multiprocessing解决PyMuPDF不支持多线程加载导致的界面卡死无响应问题,及一个PyQt5实现的简易PDF阅读器例子

    最近在用PyMuPDF实现一个PDF阅读器,发现PyMuPDF在加载某些epub时耗时非常长,有的长达10几秒,会导致界面卡死无响应. 尝试用多线程后台加载,发现还是不能解决问题,和作者交流(issu ...

  8. NOIP2014 day2 t2 寻找道路

    寻找道路 NOIP2014 day2 t2 描述 在有向图 G 中,每条边的长度均为 1,现给定起点和终点,请你在图中找一条从起点到 终点的路径,该路径满足以下条件: 1.路径上的所有点的出边所指向的 ...

  9. JavaScrip——插入地图

    具体操作步骤:1.百度搜索:百度地图生成器 2.打开第一个,复制网址http://api.map.baidu.com/lbsapi/creatmap/index.html,打开3.页面显示为 4.根据 ...

  10. 函数的arguments

    1.arguments a.只能在函数内部被访问. b.arguments是一个伪数组(有下标索引,可以存放多个值,但是他里面没有数组的方法.) c.arguments里面存的是什么?函数的实际参数传 ...