『比赛』2016 四川省赛 Around the World

题目链接:
https://www.bnuoj.com/v3/contest_show.php?cid=8520#problem/H

转载声明:http://blog.youkuaiyun.com/miracle_ma/article/details/52727420

个人感想:
这次重现省赛又来了一题best定理题目,让我感觉头晕脑胀哦,搞懂了那个best定理公式之后,其实发现,并不是特别难,这道题好就好在不用去建图,否则也是很难的哦, 还好树根都给你了,那么这道题就简单多了,C(2c,c):对于每个点的路径先选c条出来当作出度边,然后在C(c,1)选一条边来做有向树的个数,便可以完成best定理tw这块,然后就套公式,这道题目就完成了… ╮(╯▽╰)╭,真的好难啊…我这种弱鸡还是不行啊…

分析:best定理,矩阵树定理

代码:

/* Author:GavinjouElephant
 * Title:
 * Number:
 * main meanning:
 *
 *
 *
 */


#include <iostream>
using namespace std;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <cctype>
#include <vector>
#include <set>
#include <cstdlib>
#include <map>
#include <queue>
//#include<initializer_list>
//#include <windows.h>
//#include <fstream>
//#include <conio.h>
#define MaxN 0x7fffffff
#define MinN -0x7fffffff
#define lson 2*k
#define rson 2*k+1
typedef long long ll;
const int INF=0x3f3f3f3f;
const int maxn=2e6+10;
int Scan()//读入整数外挂.
{
    int res = 0, ch, flag = 0;

    if((ch = getchar()) == '-')             //判断正负
        flag = 1;

    else if(ch >= '0' && ch <= '9')           //得到完整的数
        res = ch - '0';
    while((ch = getchar()) >= '0' && ch <= '9' )
        res = res * 10 + ch - '0';
    return flag ? -res : res;
}
 void Out(int a)    //输出外挂
 {
     if(a>9)
         Out(a/10);
     putchar(a%10+'0');
 }

 ll deg[100005];
 ll fac[maxn];
 ll mod=1e9+7;
 void init()
 {
     fac[0]=1;
     for(ll i=1;i<maxn;i++)
     {
         fac[i]=(fac[i-1]*i)%mod;
     }
 }
 ll ans;
 int n;

 ll qmod(ll a,ll b,ll M)
 {
     ll res=1;
     while(b)
     {
        if(b&1)res=(res*a)%M;
        a=(a*a)%M;
        b>>=1;
     }
     return res%M;
 }
 ll C(ll n,ll m)
 {
     return (fac[n]*qmod(fac[m],mod-2,mod)%mod)*qmod(fac[n-m],mod-2,mod)%mod;
 }
int main()
{
#ifndef ONLINE_JUDGE
    freopen("coco.txt","r",stdin);
    freopen("lala.txt","w",stdout);
#endif
    init();
    while(scanf("%d",&n)!=EOF)
    {
        ll a,b,c;
        memset(deg,0,sizeof(deg));
        ans=1;
        for(int i=1;i<n;i++)
        {
            cin>>a>>b>>c;
            deg[a]+=c;
            deg[b]+=c;
            ans=(ans*C(2*c,c))%mod*c%mod;
        }
        for(int i=1;i<=n;i++) ans=(ans*fac[deg[i]-1]%mod);
        ans=(ans*deg[1])%mod;
        cout<<ans<<endl;
    }

    return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值