結果

問題 No.2377 SUM AND XOR on Tree
ユーザー ニックネームニックネーム
提出日時 2023-07-07 23:15:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 3,724 ms / 4,000 ms
コード長 533 bytes
コンパイル時間 117 ms
コンパイル使用メモリ 10,888 KB
実行使用メモリ 50,652 KB
最終ジャッジ日時 2023-09-29 00:59:18
合計ジャッジ時間 72,129 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,912 KB
testcase_01 AC 16 ms
7,868 KB
testcase_02 AC 16 ms
7,832 KB
testcase_03 AC 16 ms
7,788 KB
testcase_04 AC 16 ms
7,792 KB
testcase_05 AC 16 ms
7,804 KB
testcase_06 AC 16 ms
7,744 KB
testcase_07 AC 16 ms
7,828 KB
testcase_08 AC 3,724 ms
35,720 KB
testcase_09 AC 3,596 ms
35,776 KB
testcase_10 AC 3,546 ms
35,648 KB
testcase_11 AC 3,623 ms
35,704 KB
testcase_12 AC 3,671 ms
35,696 KB
testcase_13 AC 3,698 ms
35,544 KB
testcase_14 AC 3,509 ms
34,488 KB
testcase_15 AC 3,653 ms
35,356 KB
testcase_16 AC 3,617 ms
34,716 KB
testcase_17 AC 3,626 ms
35,088 KB
testcase_18 AC 20 ms
7,816 KB
testcase_19 AC 21 ms
7,964 KB
testcase_20 AC 20 ms
7,916 KB
testcase_21 AC 21 ms
7,832 KB
testcase_22 AC 20 ms
7,848 KB
testcase_23 AC 3,012 ms
26,864 KB
testcase_24 AC 3,031 ms
26,748 KB
testcase_25 AC 3,718 ms
35,888 KB
testcase_26 AC 3,350 ms
50,652 KB
testcase_27 AC 3,337 ms
50,552 KB
testcase_28 AC 3,375 ms
50,504 KB
testcase_29 AC 2,348 ms
33,216 KB
testcase_30 AC 2,375 ms
33,200 KB
testcase_31 AC 2,351 ms
33,224 KB
testcase_32 AC 2,158 ms
35,316 KB
testcase_33 AC 2,150 ms
35,396 KB
testcase_34 AC 2,153 ms
35,280 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit
setrecursionlimit(10**7)
n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
    u,v = map(int,input().split())
    adj[u-1].append(v-1); adj[v-1].append(u-1)
a = list(map(int,input().split()))
mod = 998244353; ans = 0
def dfs(v,p):
    v0 = a[v]>>i&1^1; v1 = a[v]>>i&1
    for c in adj[v]:
        if c==p: continue
        c0,c1 = dfs(c,v)
        v0,v1 = (v0*c0+v1*c1+v0*c1)%mod,(v0*c1+v1*c0+v1*c1)%mod
    return v0,v1
for i in range(30): ans += (1<<i)*dfs(0,-1)[1]
print(ans%mod)
0