SP104 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.
输入输出格式
输入格式:
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
MatrixTree定理的裸题
记录给出的图中每个点的度数矩阵与邻接矩阵
做差
高斯消元
把对角线乘起来
输出
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
const int MAXN=3001;
const double eps=1e-12;
inline int read()
{
char c=getchar();int x=0,f=1;
while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
return x*f;
}
double G[MAXN][MAXN],a[MAXN][MAXN];
char s[MAXN][MAXN];
int xx[5]={0,-1,+1,0,0};
int yy[5]={0,0,0,-1,+1};
int N,M;
int dcmp(int x)
{
if(x<=eps||x>=-eps) return 0;
else return x<0?-1:1;
}
void Gauss()
{
N--;
for(int i=1;i<=N;i++)//每一行
{
int mx=i;
for(int j=i+1;j<=N;j++)//下面的每一行
if(dcmp(G[mx][i]-G[j][i])<0) mx=j;
if(mx!=i) swap(G[i],G[mx]);
if(!G[i][i]) {printf("0n");return ;}
for(int j=i+1;j<=N;j++)
{
double t=G[j][i]/G[i][i];
for(int k=i;k<=N+1;k++)
G[j][k]-=t*G[i][k];
}
}
double ans=1;
for(int i=1;i<=N;i++) ans=ans*G[i][i];
printf("%.0fn",abs(ans));
}
int main()
{
int T=read();
while(T--)
{
memset(G,0,sizeof(G));
N=read(),M=read();
for(int i=1;i<=M;i++)
{
int x=read(),y=read();
G[x][x]++;G[y][y]++;
G[x][y]--;G[y][x]--;
}
Gauss();
}
return 0;
}
- python常用知识梳理
- 如何打击“假货、高仿”类小程序
- centos 6x系统下源码安装mysql操作记录
- 【3】利用Word模板生成文档的总结
- 【2】快速代码集的由来及概览
- silverlight数据绑定模式TwoWay,OneWay,OneTime的研究
- Silverlight数据绑定/IValueConverter学习笔记
- silverlight:DeepZoom版的图片局部放大效果
- Linq之ToDictionary<TSource, TKey, TElement>的写法
- vs.net的调试小技巧之#define debug(适合新手)
- byte[]数组下标的最大值
- silverlight图片局部放大效果
- 局域网与互联网环境下MTU的快速确定方法
- 【4】通过简化的正则表达式处理字符串
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- nodejs错误:PayloadTooLargeError: request entity too large
- 富文本编辑器 tinymce 的使用
- dotnet core 在 MAC 系统下删除应用程序自己后调 Process Start 方法将会抛出 Win32 异常
- 如何从高德获取地铁数据
- Yaconf - windows 环境下的高性能配置操作
- [ 物联网篇 ] 26 -ALSA Plug 中 multi 的应用
- LeetCode 1546. Maximum Number of Non-Overlapping Subarrays With Sum Equals Target(动态规划)
- HTML加载顺序
- 基于飞桨PaddleClas实现轧钢带表面缺陷分类,top1准确率可达100%
- 01Python的基本的数据结构之List
- 02Python数据结构之再谈List的常用操作
- 03Python List不得不知的操作之改、查
- 04Python基础之字符串Str
- 05Python元组tuple的个性
- Tkinter Canvas