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. 利用ST MCU内部的基准参考电压监测电源电压及其它

    源: 利用ST MCU内部的基准参考电压监测电源电压及其它

  2. 一键配置IP地址脚本

    #/bin/bash NETPWD='/etc/sysconfig/network-scripts/' read -p "please enten net num(1,2,3,4) : &q ...

  3. Oracle 事务处理

    事务的四大特性 1.原子性(Atomicity) 事务的原子性是指事务中包含的所有操作要么都做,要么都不做,保证数据库是一致的. 2.一致性(Consistency) 一致性是指数据库在事务操作前和事 ...

  4. Linux内核模块编写详解

    内核编程常常看起来像是黑魔法,而在亚瑟 C 克拉克的眼中,它八成就是了.Linux内核和它的用户空间是大不相同的:抛开漫不经心,你必须小心翼翼,因为你编程中的一个bug就会影响到整个系统,本文给大家介 ...

  5. SQL查询以某个字母开头

    select * from a where left(a.name, 1)='H'; 或 select * from a where a.name REGEXP ''^(B|S)'';

  6. Effective C++ 条款12:复制对象时勿忘其每一个成分

    void logCall(const std::string& funcName); class Customer { public: ... Customer (const Customer ...

  7. tp添加分页

    //分页开始 $count=M('article')->where($condition)->count(); $p = intval($p) > 0 ? $p : 1; $page ...

  8. 用户iis可以用外网ip访问,用内网访问报错404

    如下,没有添加内网ip绑定

  9. oracle between、 all、 in 和 exists的区别,模糊查询、4个正则表达式

    --条件比较 /* =,!=,<>,<,>,<=,>=, any,some,all is null,is not null between x and y in(l ...

  10. Redis_01

    http://redis.io/ http://www.yiibai.com/redis/redis_quick_guide.html X