SP104 HIGH - Highways
题意
就是要你求无向图的生成树个数。\(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的更多相关文章
- SP104 Highways (矩阵树,高斯消元)
矩阵树定理裸题 //#include <iostream> #include <cstdio> #include <cstring> #include <al ...
- H:Highways
总时间限制: 1000ms 内存限制: 65536kB描述The island nation of Flatopia is perfectly flat. Unfortunately, Flatopi ...
- Highways(prim & MST)
Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 23421 Accepted: 10826 Descri ...
- poj2485 Highways
Description The island nation of Flatopia is perfectly flat. Unfortunately, Flatopia has no public h ...
- poj 2485 Highways 最小生成树
点击打开链接 Highways Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19004 Accepted: 8815 ...
- poj 2485 Highways
题目连接 http://poj.org/problem?id=2485 Highways Description The island nation of Flatopia is perfectly ...
- POJ 1751 Highways (最小生成树)
Highways Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit Sta ...
- POJ 1751 Highways (最小生成树)
Highways 题目链接: http://acm.hust.edu.cn/vjudge/contest/124434#problem/G Description The island nation ...
- UVa 1393 (容斥原理、GCD) Highways
题意: 给出一个n行m列的点阵,求共有多少条非水平非竖直线至少经过其中两点. 分析: 首先说紫书上的思路,编程较简单且容易理解.由于对称性,所以只统计“\”这种线型的,最后乘2即是答案. 枚举斜线包围 ...
随机推荐
- cocos2d-x与着色器设计--入门篇(游云凌天原创)
http://blog.csdn.net/danjinxiangsi/article/details/43949955 着色器(Shader)应用与计算机图形学领域,指一组提供计算机图形资源在渲染时执 ...
- cache工作原理
转:http://www.360doc.com/content/11/0307/21/3791508_99049437.shtml
- MyEclipse激活失败
最近从MyEclipse2014升级MyEclipse2015,结果按照MyEclipse2014的方式激活2015总是失败,显示错误如下图所示: 反复实验,怎么也不能成功激活,最终找到方法 很多情况 ...
- 机器学习中的numpy库
日常学习中总是遇到数据需要处理等问题,这时候我们就可以借助numpy这个工具来做一些有意思的事. 1.生成随机数的几种方式 x=np.random.random(12) ###生成12 ...
- jQuery多级联动美化版Select下拉框
在线演示 本地下载
- CSS3鼠标悬停8种动画特效
在线演示 本地下载
- Hungry Rabbit
Problem C. Hungry Rabbit Input file: hungry.in Output file: hungry.out Time limit: 10 seconds Memory ...
- Spring_属性配置细节
XML 代码: <!-- 使用构造器注入属性值的位置和参数的类型!以区分重载的构造器! --> <bean id="car1" class="com.h ...
- hive 导出数据到本地
有时候需要将hive库中的部分数据导入至本地,这样子做可视化和小规模的数据挖掘实验都是比较方便的.数据导入至本地的HQL语法如下: INSERT OVERWRITE [LOCAL] DIRECTORY ...
- EntityFramework之领域驱动设计实践
EntityFramework之领域驱动设计实践 - 前言 EntityFramework之领域驱动设计实践 (一):从DataTable到EntityObject EntityFramework之领 ...