結果

問題 No.1843 Tree ANDistance
ユーザー 👑 rin204rin204
提出日時 2022-05-04 18:30:56
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,988 ms / 2,000 ms
コード長 806 bytes
コンパイル時間 252 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 234,348 KB
最終ジャッジ日時 2023-09-16 22:42:26
合計ジャッジ時間 16,111 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 506 ms
125,556 KB
testcase_01 AC 510 ms
125,588 KB
testcase_02 AC 1,988 ms
223,668 KB
testcase_03 AC 878 ms
232,768 KB
testcase_04 AC 484 ms
125,312 KB
testcase_05 AC 423 ms
131,416 KB
testcase_06 AC 433 ms
131,492 KB
testcase_07 AC 446 ms
123,300 KB
testcase_08 AC 495 ms
124,284 KB
testcase_09 AC 890 ms
224,076 KB
testcase_10 AC 840 ms
234,348 KB
testcase_11 AC 504 ms
124,872 KB
testcase_12 AC 409 ms
126,228 KB
testcase_13 AC 436 ms
126,376 KB
testcase_14 AC 111 ms
78,204 KB
testcase_15 AC 114 ms
78,224 KB
testcase_16 AC 109 ms
79,544 KB
testcase_17 AC 105 ms
79,264 KB
testcase_18 AC 82 ms
76,168 KB
testcase_19 AC 108 ms
78,124 KB
testcase_20 AC 102 ms
78,424 KB
testcase_21 AC 64 ms
71,184 KB
testcase_22 AC 62 ms
71,472 KB
testcase_23 AC 62 ms
71,432 KB
testcase_24 AC 66 ms
71,684 KB
testcase_25 AC 64 ms
71,652 KB
testcase_26 AC 64 ms
71,468 KB
testcase_27 AC 65 ms
71,440 KB
testcase_28 AC 345 ms
115,304 KB
testcase_29 AC 252 ms
102,872 KB
testcase_30 AC 418 ms
154,548 KB
testcase_31 AC 703 ms
213,200 KB
testcase_32 AC 363 ms
115,488 KB
testcase_33 AC 164 ms
91,112 KB
testcase_34 AC 283 ms
110,660 KB
testcase_35 AC 69 ms
71,444 KB
testcase_36 AC 68 ms
71,644 KB
testcase_37 AC 71 ms
71,444 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')
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
        else:
            pass
        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]
            else:
                pass
        
    
dfs(0, -1)
print(ans)
0