vjudge

luogu

题意

就是要你求无向图的生成树个数。\(n\le 12\),保证答案不爆\(long long\)。

sol

矩阵树定理直接上。

如果怕掉精可以写整数意义下的高斯消元,需要辗转相除,复杂度多个\(\log\)

code

#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
int gi()
{
int x=0,w=1;char ch=getchar();
while ((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
if (ch=='-') w=0,ch=getchar();
while (ch>='0'&&ch<='9') x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return w?x:-x;
}
int n,m;ll a[20][20],ans;
int main()
{
int T=gi();
while (T--)
{
n=gi();m=gi();ans=1;
memset(a,0,sizeof(a));
while (m--)
{
int u=gi(),v=gi();
a[u][u]++;a[v][v]++;
a[u][v]--;a[v][u]--;
}
for (int i=2;i<=n;++i)
{
for (int j=i+1;j<=n;++j)
while (a[j][i])
{
ll t=a[i][i]/a[j][i];
for (int k=i;k<=n;++k) a[i][k]-=t*a[j][k],swap(a[i][k],a[j][k]);
ans=-ans;
}
ans*=a[i][i];
}
printf("%lld\n",ans);
}
return 0;
}

SP104 HIGH - Highways的更多相关文章

  1. SP104 Highways (矩阵树,高斯消元)

    矩阵树定理裸题 //#include <iostream> #include <cstdio> #include <cstring> #include <al ...

  2. H:Highways

    总时间限制: 1000ms 内存限制: 65536kB描述The island nation of Flatopia is perfectly flat. Unfortunately, Flatopi ...

  3. Highways(prim & MST)

    Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23421   Accepted: 10826 Descri ...

  4. poj2485 Highways

    Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...

  5. poj 2485 Highways 最小生成树

    点击打开链接 Highways Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 19004   Accepted: 8815 ...

  6. poj 2485 Highways

    题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly ...

  7. POJ 1751 Highways (最小生成树)

    Highways Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Sta ...

  8. POJ 1751 Highways (最小生成树)

    Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...

  9. UVa 1393 (容斥原理、GCD) Highways

    题意: 给出一个n行m列的点阵,求共有多少条非水平非竖直线至少经过其中两点. 分析: 首先说紫书上的思路,编程较简单且容易理解.由于对称性,所以只统计“\”这种线型的,最后乘2即是答案. 枚举斜线包围 ...

随机推荐

  1. Arrays.asList()与toArray()

    Arrays.asList() 使用Arrays.asList()把数组转换成集合时,不能使用用于修改集合的方法(例如add.remove.clear),这将导致跑出UnsupportOperatio ...

  2. SpringBoot 通用Error设计

    在项目中需要设计统一的错误消息,通常使用枚举类定义"错误码"与"错误消息": 并且也可以做错误消息自定义. 定义通过错误接口类:CommonError publ ...

  3. infa dos命令

    informatica8.6用dos命令执行作业的命令: pmcmd startworkflow -sv integration -d Domain_BlueBreezeq -u Administra ...

  4. java 判断对象的所有属性是否为空解决方案

    public static boolean allfieldIsNUll(Object o){ try{ for(Field field:o.getClass().getDeclaredFields( ...

  5. C语言查找算法之顺序查找、二分查找(折半查找)

    C语言查找算法之顺序查找.二分查找(折半查找),最近考试要用到,网上也有很多例子,我觉得还是自己写的看得懂一些. 顺序查找 /*顺序查找 顺序查找是在一个已知无(或有序)序队列中找出与给定关键字相同的 ...

  6. MySQL安装详解图文版(V5.5 For Windows)

    MySQL在Windows中会得到越来越广泛的应用.故整理MySQL安装详解如下,以备不时之需.安装环境:Windows Server 2003 [32bit NTFS]版本信息:MySQL 5.5. ...

  7. 简易的解决方式linker command failed with exit code 1 (use -v to see invocation)

    linker command failed with exit code 1 (use -v to see invocation) 遇到这个问题先不要慌,不用纠结是不是自己改动了什么代码导致的. 长话 ...

  8. LeetCode第[34]题(Java):Search for a Range

    题目:搜索目标范围 难度:Medium 题目内容: Given an array of integers nums sorted in ascending order, find the starti ...

  9. Web2.0 TA 问题记录

    记录一下上学期在当Web2.0 TA的时候遇到过的小朋友们问过的问题,可能会成为以后我开发上遇到的问题. 1. 元素的背景默认是boader origin的,也就是说是从边框开始延伸的. 但如果对bo ...

  10. PowerShell 在hyper-v中创建虚拟机

    # This script configures the Hyper-V machines used for the 50331 Course. # PowerShell 3.0 and Window ...