牛客国庆集训派对Day3H-Travel

牛客国庆集训派对Day3H-Travel
题解:
这一题一开始以为是树上问题,其实仔细一想与树一点关系都没有。
m1m-1条边将这个树划分为mm个区域,这就代表了mm次旅游,然后求其全排列就是答案。
ans=Cn1m1m!ans=C_{n-1}^{m-1}*m!
CodeCode:

#include<iostream>
using namespace std;
const int mod=1e9+7;
int n,m;
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        int a,b;
        for(int i=0;i<n-1;++i)scanf("%d%d",&a,&b);
        long long ans=1;
        for(int i=n-1;i>n-m;--i)ans=1ll*i*ans%mod;
        printf("%lld\n",1ll*ans*m%mod);
    }
}