結果

問題 No.758 VVVVV
ユーザー kotatsugamekotatsugame
提出日時 2020-03-05 17:50:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 72 ms / 2,000 ms
コード長 641 bytes
コンパイル時間 790 ms
コンパイル使用メモリ 72,680 KB
実行使用メモリ 9,772 KB
最終ジャッジ日時 2024-04-22 03:11:31
合計ジャッジ時間 2,412 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 4 ms
6,812 KB
testcase_01 AC 3 ms
6,940 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 64 ms
9,600 KB
testcase_04 AC 32 ms
7,996 KB
testcase_05 AC 22 ms
7,496 KB
testcase_06 AC 20 ms
7,552 KB
testcase_07 AC 65 ms
9,584 KB
testcase_08 AC 32 ms
8,192 KB
testcase_09 AC 13 ms
7,256 KB
testcase_10 AC 23 ms
7,632 KB
testcase_11 AC 70 ms
9,720 KB
testcase_12 AC 18 ms
7,424 KB
testcase_13 AC 23 ms
7,588 KB
testcase_14 AC 13 ms
7,116 KB
testcase_15 AC 9 ms
7,092 KB
testcase_16 AC 10 ms
6,944 KB
testcase_17 AC 58 ms
9,160 KB
testcase_18 AC 31 ms
7,936 KB
testcase_19 AC 72 ms
9,728 KB
testcase_20 AC 20 ms
7,552 KB
testcase_21 AC 22 ms
7,552 KB
testcase_22 AC 70 ms
9,772 KB
testcase_23 AC 3 ms
6,944 KB
testcase_24 AC 3 ms
6,944 KB
testcase_25 AC 3 ms
6,944 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:32:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   32 | main()
      | ^~~~

ソースコード

diff #

#include<iostream>
#include<vector>
using namespace std;
int N;
vector<int>G[1<<17];
int ec;
void dfs(int u,int p)
{
	bool isr=true;
	for(int v:G[u])
	{
		if(v!=p)
		{
			dfs(v,u);
			isr=false;
		}
	}
	if(isr)ec++;
}
long mod=1e9+7;
long power(long a,long b){return b?power(a*a%mod,b/2)*(b%2?a:1)%mod:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%mod;
		y=y*i%mod;
	}
	return x*power(y,mod-2)%mod;
}
main()
{
	cin>>N;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1);
	cout<<comb(N-1,ec-1)*comb(N-2,ec-1)%mod*power(ec,mod-2)%mod<<endl;
}
0