結果

問題 No.2214 Products on Tree
ユーザー mkawa2mkawa2
提出日時 2023-02-14 16:45:33
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 431 ms / 3,000 ms
コード長 1,388 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 87,216 KB
実行使用メモリ 146,756 KB
最終ジャッジ日時 2023-09-24 05:21:47
合計ジャッジ時間 14,286 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
71,328 KB
testcase_01 AC 64 ms
71,396 KB
testcase_02 AC 60 ms
71,296 KB
testcase_03 AC 402 ms
127,016 KB
testcase_04 AC 383 ms
131,740 KB
testcase_05 AC 391 ms
122,020 KB
testcase_06 AC 252 ms
105,936 KB
testcase_07 AC 124 ms
86,132 KB
testcase_08 AC 109 ms
82,004 KB
testcase_09 AC 146 ms
91,660 KB
testcase_10 AC 257 ms
113,788 KB
testcase_11 AC 151 ms
91,380 KB
testcase_12 AC 164 ms
91,320 KB
testcase_13 AC 417 ms
127,160 KB
testcase_14 AC 431 ms
125,616 KB
testcase_15 AC 419 ms
127,236 KB
testcase_16 AC 417 ms
127,216 KB
testcase_17 AC 420 ms
128,452 KB
testcase_18 AC 253 ms
118,256 KB
testcase_19 AC 264 ms
120,256 KB
testcase_20 AC 236 ms
114,004 KB
testcase_21 AC 204 ms
109,840 KB
testcase_22 AC 328 ms
132,108 KB
testcase_23 AC 62 ms
71,544 KB
testcase_24 AC 60 ms
71,312 KB
testcase_25 AC 60 ms
71,288 KB
testcase_26 AC 62 ms
71,200 KB
testcase_27 AC 60 ms
71,436 KB
testcase_28 AC 182 ms
117,632 KB
testcase_29 AC 122 ms
88,732 KB
testcase_30 AC 230 ms
144,492 KB
testcase_31 AC 327 ms
141,428 KB
testcase_32 AC 329 ms
146,756 KB
testcase_33 AC 212 ms
131,528 KB
testcase_34 AC 215 ms
131,440 KB
testcase_35 AC 321 ms
132,504 KB
testcase_36 AC 315 ms
132,152 KB
testcase_37 AC 231 ms
134,612 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = (1 << 63)-1
# inf = (1 << 31)-1
# md = 10**9+7
md = 998244353

n = II()
to = [[] for _ in range(n)]
for _ in range(n-1):
    u, v = LI1()
    to[u].append(v)
    to[v].append(u)

parent, depth = [-1]*n, [0]*n
def dfs(root=0):
    uu, stack, vis = [], [root], [0]*n
    vis[root] = 1
    while stack:
        u = stack.pop()
        uu.append(u)
        for v in to[u]:
            if vis[v]: continue
            vis[v] = 1
            parent[v] = u
            stack.append(v)
    return uu

uu = dfs()
dp = [[1, 1] for _ in range(n)]
for u in uu[:0:-1]:
    p = parent[u]
    dp[p] = [dp[p][0]*(dp[u][1]+dp[u][0]), dp[p][0]*dp[u][1]%md+dp[p][1]*(dp[u][0]+dp[u][1])%md]
    dp[p][0] %= md
    dp[p][1] %= md

print(dp[0][1])
0