結果

問題 No.758 VVVVV
ユーザー chocoruskchocorusk
提出日時 2018-12-06 02:11:21
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 1,195 bytes
コンパイル時間 600 ms
コンパイル使用メモリ 86,540 KB
実行使用メモリ 10,496 KB
最終ジャッジ日時 2024-04-22 02:59:53
合計ジャッジ時間 2,180 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
7,296 KB
testcase_01 AC 4 ms
7,296 KB
testcase_02 AC 3 ms
7,168 KB
testcase_03 AC 65 ms
10,240 KB
testcase_04 AC 31 ms
8,704 KB
testcase_05 AC 23 ms
8,192 KB
testcase_06 AC 21 ms
8,320 KB
testcase_07 AC 63 ms
10,240 KB
testcase_08 AC 33 ms
8,704 KB
testcase_09 AC 14 ms
7,680 KB
testcase_10 AC 25 ms
8,448 KB
testcase_11 AC 72 ms
10,496 KB
testcase_12 AC 18 ms
8,064 KB
testcase_13 AC 23 ms
8,320 KB
testcase_14 AC 14 ms
7,680 KB
testcase_15 AC 10 ms
7,552 KB
testcase_16 AC 11 ms
7,680 KB
testcase_17 AC 57 ms
9,856 KB
testcase_18 AC 31 ms
8,704 KB
testcase_19 AC 68 ms
10,368 KB
testcase_20 AC 20 ms
8,064 KB
testcase_21 AC 22 ms
8,192 KB
testcase_22 AC 70 ms
10,368 KB
testcase_23 AC 4 ms
7,296 KB
testcase_24 AC 4 ms
7,296 KB
testcase_25 AC 4 ms
7,296 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k>0){
        if(k%2==1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k/=2;
    }
    return ans;
}
ll inv(ll a){
	return powmod(a, MOD-2);
}
int main()
{
	int n;
	cin>>n;
	if(n==1){
	    cout<<1<<endl;
	    return 0;
	}
	vector<int> g[100000];
	for(int i=0; i<n-1; i++){
		int a, b;
		cin>>a>>b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}
	int m=0;
	for(int i=1; i<n; i++){
		if(g[i].size()==1) m++;
	}
	if(m==1){
		cout<<1<<endl;
		return 0;
	}
	ll f[100001];
	f[0]=1;
	for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
	ll invf[100001];
	invf[n]=inv(f[n]);
	for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
	cout<<f[n-1]*invf[n-m]%MOD*invf[m-1]%MOD*f[n-2]%MOD*invf[m-1]%MOD*invf[n-m-1]%MOD*inv(m)%MOD<<endl;
	return 0;
}
0