結果

問題 No.2047 Path Factory
ユーザー sapphire__15sapphire__15
提出日時 2022-05-23 23:28:55
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 579 ms / 2,000 ms
コード長 712 bytes
コンパイル時間 116 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 49,408 KB
最終ジャッジ日時 2024-04-23 13:28:23
合計ジャッジ時間 7,767 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
10,752 KB
testcase_01 AC 29 ms
10,752 KB
testcase_02 AC 28 ms
10,752 KB
testcase_03 AC 28 ms
10,752 KB
testcase_04 AC 27 ms
10,752 KB
testcase_05 AC 25 ms
10,752 KB
testcase_06 AC 25 ms
10,752 KB
testcase_07 AC 307 ms
21,248 KB
testcase_08 AC 245 ms
19,200 KB
testcase_09 AC 296 ms
20,736 KB
testcase_10 AC 404 ms
24,576 KB
testcase_11 AC 239 ms
19,072 KB
testcase_12 AC 158 ms
15,872 KB
testcase_13 AC 160 ms
16,128 KB
testcase_14 AC 265 ms
19,584 KB
testcase_15 AC 323 ms
21,376 KB
testcase_16 AC 242 ms
20,340 KB
testcase_17 AC 236 ms
19,824 KB
testcase_18 AC 277 ms
22,512 KB
testcase_19 AC 327 ms
24,948 KB
testcase_20 AC 488 ms
31,468 KB
testcase_21 AC 275 ms
21,864 KB
testcase_22 AC 73 ms
13,440 KB
testcase_23 AC 96 ms
13,952 KB
testcase_24 AC 86 ms
13,440 KB
testcase_25 AC 453 ms
49,408 KB
testcase_26 AC 579 ms
43,904 KB
testcase_27 AC 498 ms
27,648 KB
testcase_28 AC 402 ms
24,960 KB
testcase_29 AC 28 ms
10,880 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(200000)
MOD = 998244353

N = int(input())
edge = [[] for _ in range(N)]
for i in range(N-1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edge[u].append(v)
    edge[v].append(u)

def dfs(now, prv = -1):
    # must, can cannot
    subDp = (1, 0, 0)
    for nxt in edge[now]:
        if nxt == prv: continue
        child = dfs(nxt, now)
        connect    = child[0] + child[1]
        disConnect = child[1] + child[2]
        subDp = (
            subDp[0] * disConnect % MOD,
            (subDp[0] * connect + subDp[1] * disConnect) % MOD,
            (subDp[1] * connect + subDp[2] * disConnect) % MOD
        )
    return subDp

print(sum(dfs(0)[1:]) % MOD)
0