题目链接:Around the World

题意:

给你n个点,有n-1条边,现在这n-1条边又多增加了ci*2-1条边,问你有多少条欧拉回路

题解:

套用best定理

Best Theorem:有向图中以 i 为起点的欧拉回路个数为以 i 为根的树形图个数 ×(( 每个点 度数 −1)!)。

Matrix Tree Theorem:以 i 为根的树形图个数 = 基尔霍夫矩阵去掉第 i 行第 i 列的行列 式。

从某个点 i 出发并回到 i 的欧拉回路个数 = 以 i 为起点的欧拉回路个数 ×i 的度数。

 #include<cstdio>
#include<cstring>
#define F(i,a,b) for(int i=a;i<=b;i++)
typedef long long ll; const int N=1e5+,P=1e9+,M=2e6;
long long fact[M+];
int deg[N],n; ll qpow(ll a,ll n){
ll ans=;
while(n){
if(n&) ans=ans*a%P;
a=a*a%P,n>>=;
}
return ans;
}
ll C(int n,int m){return (fact[n]*qpow(fact[m],P-)%P)*qpow(fact[n-m],P-)%P;} int main(){
fact[]=;
F(i,,)fact[i]=fact[i-]*i%P;
scanf("%d",&n);
ll ans=;
memset(deg,,sizeof(deg));
F(i,,n-){
int a,b,c;
scanf("%d%d%d",&a,&b,&c);
deg[a]+=c,deg[b]+=c,ans=(ans*C(*c,c)%P)*c%P;
}
F(i,,n)ans=ans*fact[deg[i]-]%P;
printf("%lld\n",ans*deg[]%P);
return ;
}

2016弱校联盟十一专场10.2——Around the World的更多相关文章

  1. 2016弱校联盟十一专场10.5---As Easy As Possible(倍增)

    题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8506#problem/A problem description As we know, t ...

  2. 2016弱校联盟十一专场10.3---Similarity of Subtrees(深搜+hash、映射)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52310 problem description Define the depth of a ...

  3. (2016弱校联盟十一专场10.3) D Parentheses

    题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...

  4. (2016弱校联盟十一专场10.3) B.Help the Princess!

    题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...

  5. (2016弱校联盟十一专场10.3) A.Best Matched Pair

    题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...

  6. 2016弱校联盟十一专场10.3---We don't wanna work!(STL--set的使用)

    题目链接 https://acm.bnu.edu.cn/v3/contest_show.php?cid=8504#problem/C 代码如下: #include <iostream> # ...

  7. 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)

    题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem  description In ICPCCamp, there ar ...

  8. (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search

    题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...

  9. (2016弱校联盟十一专场10.2) E.Coins

    题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...

  10. (2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci

    题目链接 题目大意就是这个,先找出下标的循环节,再快速幂对20160519取余就行了. 找出下标循环节: #include <cstdio> #include <iostream&g ...

随机推荐

  1. Lua 中的string库(字符串函数库)总结

    (字符串函数库)总结 投稿:junjie 字体:[增加 减小] 类型:转载 时间:2014-11-20我要评论 这篇文章主要介绍了Lua中的string库(字符串函数库)总结,本文讲解了string库 ...

  2. git linux 多工程部署及git默认端口更改

    >> ssh-keygen -t rsa -C "your_email@youremail.com" print  Generating public/private ...

  3. MVC-工作原理

    ASP.NET MVC的原理,其实就是使用HttpModule和HttpHandler将用户的请求拦截,按照设定的路由规则解释到相应的控制器和Action,加以执行.Module是一个比较宏观一点的概 ...

  4. 浅谈javascript中stopImmediatePropagation函数和stopPropagation函数的区别

    在事件处理程序中,每个事件处理程序中间都会有一个event对象,而这个event对象有两个方法,一个是stopPropagation方法,一个是stopImmediatePropagation方法,两 ...

  5. 编译C语言单元测试框架CUnit库的方法

    引用: http://blog.csdn.net/yygydjkthh/article/details/46357421 个人备忘使用 /******************************* ...

  6. 图片翻转(Raw Image)

    int TransformImageBuffer(unsigned char* pImageBuffer, int width, int height,unsigned char* targetIma ...

  7. spring 四种依赖注入方式以及注解注入方式

    平常的java开发中,程序员在某个类中需要依赖其它类的方法,则通常是new一个依赖类再调用类实例的方法,这种开发存在的问题是new的类实例不好统一管理,spring提出了依赖注入的思想,即依赖类不由程 ...

  8. 加速Android Studio的Gradle构建速度

    在利用Android Studio做项目时,发现随着项目内资源的逐渐增多(或者项目创建时间太过久远,而又未经常打开),Android Studio的build速度也越来越慢.(P.S.在做我的CSGO ...

  9. centos redis 安装

    # wget http://download.redis.io/releases/redis-2.8.6.tar.gz # tar xzf redis-2.8.6.tar.gz # cd redis- ...

  10. ural 1100. Final Standings(数据结构)

    1100. Final Standings Time limit: 1.0 secondMemory limit: 16 MB Old contest software uses bubble sor ...