Uva10766 Organising the Organisation
题目链接戳这里
基尔霍夫矩阵裸题。构建基尔霍夫矩阵(度数矩阵-邻接矩阵),求他的任意\(n-1\)阶主子式的绝对值即为答案。
这题开始用java写,结果BigInteger太慢Tle了。
后来用c++写了个crt,不知道为什么wa了。
最后用long double强上最后输出转long long,ac了。
注意:给出的边可能有重复的。
#include<cmath>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
using namespace std;
typedef long double ld;
typedef long long ll;
#define maxn (60)
#define eps (1e-7)
int N,M,K; ld A[maxn][maxn]; ll ans;
inline ld guass()
{
ld ret = 1; bool sign = false;
for (int i = 1,j;i < N;++i)
{
for (j = i;j < N;++j) if (fabs(A[j][i]) > eps) break;
if (j == N) { sign = true; break; }
for (int k = 1;k < N;++k) swap(A[i][k],A[j][k]);
ld inv = A[i][i]; ret *= inv;
for (j = i;j < N;++j) A[i][j] /= inv;
for (j = i+1;j < N;++j)
{
ld t = A[j][i];
for (int k = i;k < N;++k) A[j][k] -= t*A[i][k];
}
}
if (sign) ret = 0;
return fabs(ret);
}
int main()
{
freopen("10766.in","r",stdin);
freopen("10766.out","w",stdout);
while (scanf("%d %d %d",&N,&M,&K) != EOF)
{
for (int i = 1;i <= N;++i)
for (int j = 1;j <= N;++j)
{
if (i != j) A[i][j] = 1;
else A[i][i] = 0;
}
while (M--)
{
int a,b; scanf("%d %d",&a,&b);
A[a][b] = A[b][a] = 0;
}
for (int i = 1;i <= N;++i)
for (int j = 1;j <= N;++j)
if (i != j&&A[i][j] > eps) A[i][i]--;
printf("%lld\n",(ll)(guass()+0.5));
}
fclose(stdin); fclose(stdout);
return 0;
}
Uva10766 Organising the Organisation的更多相关文章
- UVA10766:Organising the Organisation(生成树计数)
Organising the Organisation 题目链接:https://vjudge.net/problem/UVA-10766 Description: I am the chief of ...
- 生成树的计数(基尔霍夫矩阵):UVAoj 10766 Organising the Organisation SPOJ HIGH - Highways
HIGH - Highways In some countries building highways takes a lot of time... Maybe that's because th ...
- 「UVA10766」Organising the Organisation(生成树计数)
BUPT 2017 Summer Training (for 16) #6C 题意 n个点,完全图减去m条边,求生成树个数. 题解 注意可能会给重边. 然后就是生成树计数了. 代码 #include ...
- Organising the Organisation(uva10766)(生成树计数)
Input Output Sample Input 5 5 2 3 1 3 4 4 5 1 4 5 3 4 1 1 1 4 3 0 2 Sample Output 3 8 3 题意: 有一张图上有\( ...
- UVa 10766 Organising the Organisation(矩阵树定理)
https://vjudge.net/problem/UVA-10766 题意: 给出n, m, k.表示n个点,其中m条边不能直接连通,求生成树个数. 思路: 这也算个裸题,把可以连接的边连接起来, ...
- UVA 10766 Organising the Organisation
https://vjudge.net/problem/UVA-10766 题意: n个员工,除总经理外每个人只能有一个直接上级 有m对人不能成为直接的上下级关系 规定k为总经理 问员工分级方案 无向图 ...
- UVa 10766 Organising the Organisation (生成树计数)
题意:给定一个公司的人数,然后还有一个boss,然后再给定一些人,他们不能成为直属上下级关系,问你有多少种安排方式(树). 析:就是一个生成树计数,由于有些人不能成为上下级关系,也就是说他们之间没有边 ...
- Uva 10766 Organising the Organisation (Matrix_tree 生成树计数)
题目描述: 一个由n个部门组成的公司现在需要分层,但是由于员工间的一些小小矛盾,使得他们并不愿意做上下级,问在满足他们要求以后有多少种分层的方案数? 解题思路: 生成树计数模板题,建立Kirchhof ...
- KUANGBIN带你飞
KUANGBIN带你飞 全专题整理 https://www.cnblogs.com/slzk/articles/7402292.html 专题一 简单搜索 POJ 1321 棋盘问题 //201 ...
随机推荐
- Android应用程序所包含的四种组件和DDMS
关注用户组件 Activity 编辑文本 .玩游戏 后台进程 Service ...
- maven跳过单元测试
24.跳过单元测试 <plugin><groupId>org.apache.maven.plugins</groupId><artifactId>mav ...
- 将table内容输出为csv文件
1.创建 directory create or replace directory tt as'c:\'; SELECT * FROM DBA_OBJECTS DO WHERE DO.OBJECT_ ...
- mongodb环境部署
mongodb 环境部署 1.环境说明 安装软件:mongodb-linux-x86_64-.tgz 软件安装位置:/usr/local/mongodb 数据存放位置:/var/mongodb/dat ...
- eclipse 注释模板设置
方法注释模板 /** * @title ${enclosing_method} * @description ${todo} * ${tags} ${return_type} * @Date ${da ...
- RPC框架之Thrift
目前流行的服务调用方式有很多种,例如基于SOAP消息格式的 Web Service,基于 JSON 消息格式的 RESTful 服务等.其中所用到的数据传输方式包括 XML,JSON 等,然而 XML ...
- elasticsearch学习一、安装和配置
原文链接:http://jingyan.baidu.com/article/48206aead42b53216bd6b372.html ElasticSearch是一个基于Lucene的搜索服务器.它 ...
- 实战突击: Java Web项目整合开发(PDF)
实战突击: Java Web项目整合开发(PDF)
- HTML解析引擎:Jumony
Jumony Core首先提供了一个近乎完美的HTML解析引擎,其解析结果无限逼近浏览器的解析结果.不论是无结束标签的元素,可选结束标签的元素,或是标记属性,或是CSS选择器和样式,一切合法的,不合法 ...
- Struts2 多文件下载
Step1:导入支持jar包 commons-fileupload-1.3.1.jar commons-io-2.4.jar jstl-1.2.jar standard-1.1.2.jar commo ...