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 ...
随机推荐
- 如何去除CISCO交换机中的口令??
加电后按住交换机前面的那个按钮 灯不闪了以后松手这时交换机会进入switch:模式输入命令 flash然后 dir flash:你会发现有个 config.text 的文件 你的密码和配置都保存在那里 ...
- [置顶] Datalist嵌套datalist,页面传值,加密,数据绑定
<asp:DataList ID="dlMajor" runat="server" CssClass="dllist" OnItemD ...
- AWS RDS 使用笔记
创建VPC安全组 添加VPC子网 创建RDS子网组 创建RDS参数组 创建MySQL实例 查看RDS终端节点 使用 MySQL 监视器与数据库实例上的数据库连接 安装mysql client $ su ...
- Unity3D 之2D动画机
这里来讲解一下2D动画机的使用 2D的时候,默认的情况下,可以调用默认的站立之类的动画,然后通过触发,可以变化自己的动画. 一:将一个图切成一些一个元素 二:创建一个精灵,给精灵添加一个动画机 三:给 ...
- WKWebView无法(通过URL schemes)跳转到其他App
Custom scheme URL 在WKWebView中默认是不支持的 (但Safari可以). 我们可以通过NSError来进行一些处理从而使得程序可以正常跳转: func webView(web ...
- 使用AFNetworking进行图片上传
转载自:http://blog.csdn.net/a645258072/article/details/51728806 项目中,我们经常会用到上传图片的功能,而目前的上传图片分为两种(我只知道两种, ...
- java新手笔记17 参数
package com.yfs.javase; public class ParamDemo { public static void main(String[] args) { int a = 3, ...
- java新手笔记4 数组
1.数组 import java.util.Random; public class ArrayDemo1 { public static void main(String[] args) { int ...
- Ubuntu_14.04安装docker
Ubuntu_14.04安装docker $ sudo apt-get update $ sudo apt-get install apt-transport-https ca-certificate ...
- JDBC实现往MySQL插入百万级数据
想往某个表中插入几百万条数据做下测试, 原先的想法,直接写个循环10W次随便插入点数据试试吧,好吧,我真的很天真.... DROP PROCEDURE IF EXISTS proc_initData; ...