結果

問題 No.1843 Tree ANDistance
ユーザー 👑 rin204rin204
提出日時 2022-02-18 21:46:51
言語 PyPy3
(7.3.15)
結果
MLE  
(最新)
AC  
(最初)
実行時間 -
コード長 676 bytes
コンパイル時間 633 ms
コンパイル使用メモリ 86,884 KB
実行使用メモリ 701,252 KB
最終ジャッジ日時 2023-09-11 18:53:54
合計ジャッジ時間 19,141 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 578 ms
131,312 KB
testcase_01 AC 527 ms
128,336 KB
testcase_02 AC 1,935 ms
237,860 KB
testcase_03 AC 865 ms
233,948 KB
testcase_04 AC 561 ms
126,316 KB
testcase_05 AC 412 ms
127,272 KB
testcase_06 AC 435 ms
127,260 KB
testcase_07 AC 542 ms
126,948 KB
testcase_08 AC 525 ms
128,512 KB
testcase_09 AC 1,163 ms
408,528 KB
testcase_10 AC 873 ms
234,268 KB
testcase_11 AC 517 ms
126,140 KB
testcase_12 AC 374 ms
122,524 KB
testcase_13 AC 411 ms
123,228 KB
testcase_14 AC 131 ms
78,804 KB
testcase_15 AC 126 ms
78,028 KB
testcase_16 AC 113 ms
78,944 KB
testcase_17 AC 108 ms
79,320 KB
testcase_18 AC 84 ms
75,872 KB
testcase_19 AC 112 ms
78,524 KB
testcase_20 AC 108 ms
78,388 KB
testcase_21 AC 67 ms
71,236 KB
testcase_22 AC 70 ms
71,220 KB
testcase_23 AC 70 ms
71,320 KB
testcase_24 AC 71 ms
71,108 KB
testcase_25 AC 71 ms
71,264 KB
testcase_26 AC 70 ms
70,912 KB
testcase_27 AC 69 ms
71,336 KB
testcase_28 AC 431 ms
119,168 KB
testcase_29 AC 325 ms
106,036 KB
testcase_30 MLE -
testcase_31 AC 1,116 ms
216,216 KB
testcase_32 AC 423 ms
117,232 KB
testcase_33 AC 157 ms
90,540 KB
testcase_34 AC 257 ms
108,152 KB
testcase_35 AC 69 ms
71,160 KB
testcase_36 AC 68 ms
71,112 KB
testcase_37 AC 68 ms
71,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)
MOD = 10 ** 9 + 7

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    edges[a].append((b, c))
    edges[b].append((a, c))

dp = [[1] * 30 for _ in range(n)]
ans = 0
bi = [1 << i for i in range(30)]
def dfs(pos, bpos):
    global ans
    for npos, c in edges[pos]:
        if npos == bpos:
            continue
        dfs(npos, pos)
        for i in range(30):
            if c >> i & 1:
                ans += dp[pos][i] * dp[npos][i] * bi[i]
                ans %= MOD
                dp[pos][i] += dp[npos][i]
        
    
dfs(0, -1)
print(ans)
0