結果

問題 No.1843 Tree ANDistance
ユーザー first_vilfirst_vil
提出日時 2022-02-19 18:04:18
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,106 bytes
コンパイル時間 523 ms
コンパイル使用メモリ 87,088 KB
実行使用メモリ 369,508 KB
最終ジャッジ日時 2023-09-11 20:49:27
合計ジャッジ時間 61,749 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 AC 1,872 ms
369,508 KB
testcase_06 AC 1,939 ms
349,504 KB
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 1,764 ms
356,404 KB
testcase_13 TLE -
testcase_14 AC 822 ms
326,628 KB
testcase_15 AC 826 ms
326,324 KB
testcase_16 AC 805 ms
325,868 KB
testcase_17 AC 804 ms
326,000 KB
testcase_18 AC 781 ms
325,104 KB
testcase_19 AC 820 ms
326,368 KB
testcase_20 AC 814 ms
325,924 KB
testcase_21 AC 763 ms
319,596 KB
testcase_22 AC 757 ms
319,916 KB
testcase_23 AC 758 ms
319,852 KB
testcase_24 AC 759 ms
319,452 KB
testcase_25 AC 760 ms
319,680 KB
testcase_26 AC 759 ms
319,700 KB
testcase_27 AC 761 ms
319,516 KB
testcase_28 AC 1,756 ms
341,528 KB
testcase_29 AC 1,384 ms
340,052 KB
testcase_30 AC 1,328 ms
336,928 KB
testcase_31 AC 1,894 ms
348,380 KB
testcase_32 AC 1,846 ms
346,672 KB
testcase_33 AC 895 ms
338,012 KB
testcase_34 AC 1,445 ms
341,000 KB
testcase_35 AC 757 ms
319,904 KB
testcase_36 AC 760 ms
319,856 KB
testcase_37 AC 771 ms
319,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

int1 = lambda x: int(x) - 1

# input = lambda: sys.stdin.buffer.readline()
input = lambda: sys.stdin.readline().rstrip()
ii = lambda: int(input())
i1 = lambda: int1(input())
mi = lambda: map(int, input().split())
mi1 = lambda: map(int1, input().split())
li = lambda: list(mi())
li1 = lambda: list(mi1())
lli = lambda n: [li() for _ in range(n)]

INF = float("inf")
mod = int(1e9 + 7)
# mod = 998244353

n = ii()
g = [list() for i in range(n)]
for i in range(n - 1):
    a, b, c = mi()
    a, b = a - 1, b - 1
    g[a].append((b, c))
    g[b].append((a, c))

ans = 0
st = []
for j in range(30):
    used = [False] * n
    for i in range(n):
        if used[i]:
            continue
        st.append(i)
        used[i] = True
        cnt = 1
        while st:
            cur = st.pop()
            for to, weight in g[cur]:
                if not used[to] and weight >> j & 1:
                    st.append(to)
                    used[to] = True
                    cnt += 1
        ans += cnt * (cnt - 1) % mod * (1 << j) % mod
        ans %= mod
ans *= pow(2, mod - 2)
ans %= mod
print(ans)
0