提出 #3950379


ソースコード 拡げる

import sys
sys.setrecursionlimit(10**7)
N=int(input())
table=[[] for i in range(N)]
for i in range(N-1):
    w,v=map(int,input().split())
    table[w-1].append(v-1)
    table[v-1].append(w-1)
mod=10**9+7
f=[-1]*N
g=[-1]*N
def ser(par,son):
    if f[son]!=-1 and g[son]!=-1:
        return f[son],g[son]
    s=1
    t=1
    for grason in table[son]:
        if grason==par:
            continue
        x,y=ser(son,grason)
        s*=x
        s%=mod
        t*=(x+y)
        t%=mod
    f[son],g[son]=t,s
    return t,s
z=1
w=1
for i in table[0]:
    ser(0,i)
    z*=f[i]
    z%=mod
    w*=(f[i]+g[i])
    w%=mod
print((z+w)%mod)

提出情報

提出日時
問題 P - Independent Set
ユーザ okumura
言語 PyPy3 (2.4.0)
得点 100
コード長 662 Byte
結果 AC
実行時間 1031 ms
メモリ 218572 KiB

ジャッジ結果

セット名 All
得点 / 配点 100 / 100
結果
AC × 20
セット名 テストケース
All 0_00, 0_01, 0_02, 0_03, 1_00, 1_01, 1_02, 1_03, 1_04, 1_05, 1_06, 1_07, 1_08, 1_09, 1_10, 1_11, 1_12, 1_13, 1_14, 1_15
ケース名 結果 実行時間 メモリ
0_00 AC 161 ms 38384 KiB
0_01 AC 164 ms 38392 KiB
0_02 AC 161 ms 38256 KiB
0_03 AC 161 ms 38256 KiB
1_00 AC 159 ms 38256 KiB
1_01 AC 1031 ms 131616 KiB
1_02 AC 612 ms 63392 KiB
1_03 AC 631 ms 63776 KiB
1_04 AC 629 ms 63776 KiB
1_05 AC 628 ms 64544 KiB
1_06 AC 637 ms 63008 KiB
1_07 AC 685 ms 61064 KiB
1_08 AC 673 ms 63008 KiB
1_09 AC 678 ms 62752 KiB
1_10 AC 752 ms 68768 KiB
1_11 AC 735 ms 67872 KiB
1_12 AC 700 ms 68512 KiB
1_13 AC 702 ms 77856 KiB
1_14 AC 1001 ms 218572 KiB
1_15 AC 947 ms 112288 KiB