結果

問題 No.2214 Products on Tree
ユーザー tassei903tassei903
提出日時 2023-02-11 13:23:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 554 ms / 3,000 ms
コード長 934 bytes
コンパイル時間 1,028 ms
コンパイル使用メモリ 87,012 KB
実行使用メモリ 165,452 KB
最終ジャッジ日時 2023-09-22 11:17:14
合計ジャッジ時間 15,719 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,120 KB
testcase_01 AC 69 ms
71,124 KB
testcase_02 AC 70 ms
71,228 KB
testcase_03 AC 550 ms
125,232 KB
testcase_04 AC 536 ms
126,908 KB
testcase_05 AC 542 ms
130,840 KB
testcase_06 AC 359 ms
110,300 KB
testcase_07 AC 181 ms
85,644 KB
testcase_08 AC 156 ms
81,880 KB
testcase_09 AC 201 ms
89,608 KB
testcase_10 AC 361 ms
113,368 KB
testcase_11 AC 221 ms
93,668 KB
testcase_12 AC 254 ms
96,768 KB
testcase_13 AC 542 ms
135,576 KB
testcase_14 AC 554 ms
135,596 KB
testcase_15 AC 544 ms
135,796 KB
testcase_16 AC 531 ms
135,632 KB
testcase_17 AC 538 ms
135,556 KB
testcase_18 AC 316 ms
119,396 KB
testcase_19 AC 323 ms
122,080 KB
testcase_20 AC 303 ms
116,560 KB
testcase_21 AC 256 ms
107,112 KB
testcase_22 AC 388 ms
133,524 KB
testcase_23 AC 71 ms
71,212 KB
testcase_24 AC 70 ms
71,440 KB
testcase_25 AC 69 ms
71,440 KB
testcase_26 AC 71 ms
71,364 KB
testcase_27 AC 70 ms
71,064 KB
testcase_28 AC 249 ms
115,012 KB
testcase_29 AC 175 ms
91,840 KB
testcase_30 AC 325 ms
160,460 KB
testcase_31 AC 467 ms
165,452 KB
testcase_32 AC 415 ms
151,828 KB
testcase_33 AC 299 ms
127,400 KB
testcase_34 AC 291 ms
127,444 KB
testcase_35 AC 428 ms
137,256 KB
testcase_36 AC 433 ms
137,268 KB
testcase_37 AC 314 ms
127,532 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
mod = 998244353
n = ni()
g = [[] for i in range(n)]

for _ in range(n-1):
    u,v = na()
    u-=1
    v-=1
    g[u].append(v)
    g[v].append(u)

et = []
chi = [[] for i in range(n)]
d = [0]
seen = [0] * n
while d:
    x = d.pop()
    seen[x] = 1
    et.append(x)
    for y in g[x]:
        if seen[y] ^ 1:
            chi[x].append(y)
            d.append(y)

dp1 = [1] * n
dp2 = [1] * n
for x in et[::-1]:
    for y in chi[x]:
        dp1[x],dp2[x] = dp1[x] * dp2[y] + dp2[x] * dp1[y] + dp1[x] * dp1[y], dp2[x] * (dp2[y] + dp1[y])
        dp1[x] %= mod
        dp2[x] %= mod
        #print(x,dp1[x],dp2[x])
print(dp1[0])
0