結果

問題 No.758 VVVVV
ユーザー 37zigen37zigen
提出日時 2019-01-06 18:20:25
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,016 bytes
コンパイル時間 3,864 ms
コンパイル使用メモリ 73,804 KB
実行使用メモリ 64,992 KB
最終ジャッジ日時 2023-08-15 16:13:12
合計ジャッジ時間 17,802 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 119 ms
55,868 KB
testcase_01 WA -
testcase_02 AC 122 ms
56,088 KB
testcase_03 AC 769 ms
64,652 KB
testcase_04 AC 574 ms
60,712 KB
testcase_05 AC 490 ms
60,124 KB
testcase_06 AC 493 ms
60,504 KB
testcase_07 AC 750 ms
64,324 KB
testcase_08 AC 547 ms
60,224 KB
testcase_09 AC 385 ms
60,008 KB
testcase_10 AC 504 ms
60,752 KB
testcase_11 AC 728 ms
64,368 KB
testcase_12 AC 442 ms
60,224 KB
testcase_13 AC 488 ms
60,364 KB
testcase_14 AC 402 ms
60,288 KB
testcase_15 AC 330 ms
60,080 KB
testcase_16 AC 360 ms
60,460 KB
testcase_17 AC 689 ms
64,836 KB
testcase_18 AC 519 ms
60,376 KB
testcase_19 AC 708 ms
64,992 KB
testcase_20 AC 459 ms
60,336 KB
testcase_21 AC 437 ms
60,048 KB
testcase_22 AC 746 ms
64,232 KB
testcase_23 AC 120 ms
55,680 KB
testcase_24 AC 121 ms
55,908 KB
testcase_25 AC 127 ms
55,616 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.*;
import java.util.*;

public class Main{

    final long mo=(long)1e9+7;
    
    public static void main(String[] args){
    	new Main().run();
    }

    void run(){
	    Scanner sc=new Scanner(System.in);
    	int N=sc.nextInt();
    	int[] deg=new int[N];
    	for(int i=0;i<N-1;++i){
    	    int a=sc.nextInt();
    	    int b=sc.nextInt();
    	    --a;
    	    --b;
    	    ++deg[a];
    	    ++deg[b];
    	}
    	int n=N-1;
    	int m=0;
    	for(int i=1;i<N;++i){
    	    if(deg[i]==1)
    		++m;
    	}
    	System.out.println(narayana(n,m));
    }

    long narayana(long n,long k){
	    return inv(k)*comb(n,k-1)%mo*comb(n-1,k-1)%mo;
    }

    long comb(long n,long k){
    	long ret=1;
    	for(long i=0;i<k;++i){
    	    ret=ret*(n-i)%mo*inv(i+1)%mo;
    	}
    	return ret;
    }

    long inv(long a){
    	return pow(a,mo-2);
    }

    long pow(long a,long n){
    	long ret=1;
    	for(;n>0;n>>=1,a=a*a%mo){
    	    if(n%2==1)ret=ret*a%mo;
    	}
    	return ret;
    }
}
0