2016弱校联盟十一专场10.2——Around the World
题目链接: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的更多相关文章
- 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 ...
- 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 ...
- (2016弱校联盟十一专场10.3) D Parentheses
题目链接 把左括号看成A右括号看成B,推一下就行了.好久之前写的,推到最后发现是一个有规律的序列. #include <bits/stdc++.h> using namespace std ...
- (2016弱校联盟十一专场10.3) B.Help the Princess!
题目链接 宽搜一下就行. #include <iostream> #include<cstdio> #include<cstring> #include<qu ...
- (2016弱校联盟十一专场10.3) A.Best Matched Pair
题目链接 #include<cstdio> #include<cstring> #include<algorithm> #include<stack> ...
- 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> # ...
- 2016弱校联盟十一专场10.2---Around the World(深搜+组合数、逆元)
题目链接 https://acm.bnu.edu.cn/v3/problem_show.php?pid=52305 problem description In ICPCCamp, there ar ...
- (2016弱校联盟十一专场10.2) A.Nearest Neighbor Search
题目链接 水题,算一下就行. #include <bits/stdc++.h> using namespace std; typedef long long ll; ll x[],y[], ...
- (2016弱校联盟十一专场10.2) E.Coins
题目链接 很久之前写的了,好像是对拍打表过的,推一下就行了. #include <bits/stdc++.h> using namespace std; typedef long long ...
- (2016弱校联盟十一专场10.5) F. Fibonacci of Fibonacci
题目链接 题目大意就是这个,先找出下标的循环节,再快速幂对20160519取余就行了. 找出下标循环节: #include <cstdio> #include <iostream&g ...
随机推荐
- Hive插数据报错
报错信息: Failed with exception MetaException(message:javax.jdo.JDODataStoreException: Put request faile ...
- 单身福利来了:VR恋人为你量身定制一个女朋友
相对于传统视频体验,VR视频给人带来了更加真实的体验.特别是对于单身狗来说,能在VR中拥有一个虚拟的恋人可谓是莫大的心灵安慰.近日,上海微雁文化传媒有限公司正式发布了首款养成类手机应用VR恋人. VR ...
- sort vector - leetcode 新用法
179. Largest Number sort(num.begin(), num.end(), [](int a, int b){ return to_string(a)+to_string(b) ...
- Android中AlertDialog对话框禁止按[返回键]或[搜索键]
alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() { @Override public boolean onKey(Di ...
- 可参考的gulp资源
可参考的gulp资源 入门:https://segmentfault.com/a/1190000000435599 比较详细:https://markpop.github.io/2014/09/17/ ...
- Vim/gvim容易忘记的快捷键
正常模式==>插入模式 按i 在光标前插入 按I 在行首插入 按a 在光标后插入 按s 删除光标所在的字符再插入 按A 在行末插入 按o 在当前行之下新建行 按O 在当前行之上新建行 按S 删除 ...
- .Net 第三方工具包整理
抓取数据 Jumony (http://www.jumony.net/)是一个基于 .NET 技术,用 C# 编写的一个 HTML 引擎,其可以用来分析解读 HTML 文档中的数据,也可以修改和绑定数 ...
- some idea for my personal page
firstly, dump the old personal page source from Github to Dropbox.then the idea is: 1: make a fake s ...
- C#操作WORD换行
appWord.ActiveDocument.Bookmarks[bookMark].Select(); Word.Selection wordSelection = appWord.ActiveDo ...
- Math.round(),Math.ceil(),Math.floor()的区别
1.Math.round():根据"round"的字面意思"附近.周围",可以猜测该函数是求一个附近的整数,看下面几个例子就明白. 小数点后第一位<5 正 ...