「UVA10766」Organising the Organisation(生成树计数)
BUPT 2017 Summer Training (for 16) #6C
题意
n个点,完全图减去m条边,求生成树个数。
题解
注意可能会给重边。
然后就是生成树计数了。
代码
#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 101
#define eps (1e-8)
#define mem(x,v) memset(x,v,sizeof(x))
typedef long long ll;
using namespace std;
int n,m,k;
ll g[N][N];
int sgn(double x){
return x>eps?1:(x<-eps?-1:0);
}
ll det(int n){
int i,j,k;
ll ans=1,t;
for(i=0;i<n;++i){
for(j=i+1;j<n;++j)
while(g[j][i]){
t=g[i][i]/g[j][i];
for(k=i;k<n;++k)
g[i][k]-=g[j][k]*t;
swap(g[i],g[j]);
ans=-ans;
}
if(g[i][i]==0)return 0L;
ans=ans*g[i][i];
}
return ans;
}
int main(){
while(~scanf("%d%d%d",&n,&m,&k)){
mem(g,-1);
for(int i=0;i<n;++i)
g[i][i]=0;
for(int i=0;i<m;++i){
int u,v;
scanf("%d%d",&u,&v);
--u;--v;//!!!
g[u][v]=g[v][u]=0;
}
for(int i=0;i<n;++i)
for(int j=i+1;j<n;++j){
if(g[i][j]){
++g[i][i];
++g[j][j];
}
}
printf("%lld\n",det(n-1));
}
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 ...
- UVa 10766 Organising the Organisation (生成树计数)
题意:给定一个公司的人数,然后还有一个boss,然后再给定一些人,他们不能成为直属上下级关系,问你有多少种安排方式(树). 析:就是一个生成树计数,由于有些人不能成为上下级关系,也就是说他们之间没有边 ...
- 「考试」小P的生成树
考场上想到一半正解,没想到随机化,不然也许能够$A$掉. 题目所说的其实就是向量加法,求模长最长的向量生成树. 我们考虑对于两个向量,必然在平行边形对角线方向上,他们的投影和是最大的,长度就是对角线长 ...
- LOJ #2205. 「HNOI2014」画框 解题报告
#2205. 「HNOI2014」画框 最小乘积生成树+KM二分图带权匹配 维护一个\((\sum A,\sum B)\)的匹配下凸包,答案在这些点中产生. 具体的,凸包两端可以直接跑单独的\(A\) ...
- 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 题意: 有一张图上有\( ...
- Loj 2320.「清华集训 2017」生成树计数
Loj 2320.「清华集训 2017」生成树计数 题目描述 在一个 \(s\) 个点的图中,存在 \(s-n\) 条边,使图中形成了 \(n\) 个连通块,第 \(i\) 个连通块中有 \(a_i\ ...
- 生成树的计数(基尔霍夫矩阵):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 ...
- Uva 10766 Organising the Organisation (Matrix_tree 生成树计数)
题目描述: 一个由n个部门组成的公司现在需要分层,但是由于员工间的一些小小矛盾,使得他们并不愿意做上下级,问在满足他们要求以后有多少种分层的方案数? 解题思路: 生成树计数模板题,建立Kirchhof ...
- 「NOI2013」树的计数 解题报告
「NOI2013」树的计数 这什么神题 考虑对bfs重新编号为1,2,3...n,然后重新搞一下dfs序 设dfs序为\(dfn_i\),dfs序第\(i\)位对应的节点为\(pos_i\) 一个暴力 ...
随机推荐
- Choosing The Commander CodeForces - 817E (01字典树+思维)
As you might remember from the previous round, Vova is currently playing a strategic game known as R ...
- python 中的re模块,正则表达式
一.re模块 re模块中常用的方法. match: 默认从字符串开头开始匹配,re.match('fun', 'funny') 可以匹配出来 'fun' match(pattern, string, ...
- sqlServer问题记录
1.sql 2008 无法绑定由多个部分绑定的标示符 连接中的多个表中存在同名字段,通过设置别名访问即可 2.远程无法连接到sqlserver 计算机管理->服务与应用程序->SQL Se ...
- python selenium中如何测试360等基于chrome内核的浏览器
转自:https://blog.csdn.net/five3/article/details/50013159 直接上代码,注意是基于chrome内核的浏览器,基于ie的请替换其中的chrome方法为 ...
- babel (三) babel polly-fill
Babel includes a polyfill that includes a custom regenerator runtime and core-js. This will emulate ...
- spring核心思想:IOC(控制反转)和DI(依赖注入)
Spring有三大核心思想,分别是控制反转(IOC,Inversion Of Controller),依赖注入(DI,Dependency Injection)和面向切面编程(AOP,Aspect O ...
- GANs (Generative Adversarial Networks)
#!/usr/bin/python2.7 #coding:utf-8 import tensorflow as tf import numpy as np import matplotlib.pypl ...
- C# Note11:如何优雅地退出WPF应用程序
前言 I should know how I am supposed to exit my application when the user clicks on the Exit menu item ...
- github & markdown & collapse & table
github & markdown collapse & table https://github.com/Microsoft/TypeScript/issues/30034 GitH ...
- Ajax之Jquery封装使用举例2(Json和JsonArray处理)
本例主要使用ajax进行异步数据请求,并针对返回数据为json和jsonarray类型的数据处理. 本例中只有前端的代码,后端代码不是本文重点,故省略. 后端接口返回数据为: Json: {" ...