結果

問題 No.1843 Tree ANDistance
ユーザー first_vilfirst_vil
提出日時 2022-02-19 18:03:25
言語 PyPy3
(7.3.15)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,100 bytes
コンパイル時間 666 ms
コンパイル使用メモリ 86,892 KB
実行使用メモリ 369,360 KB
最終ジャッジ日時 2023-09-11 20:48:18
合計ジャッジ時間 59,505 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 TLE -
testcase_03 TLE -
testcase_04 TLE -
testcase_05 AC 1,755 ms
369,360 KB
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 TLE -
testcase_10 TLE -
testcase_11 TLE -
testcase_12 AC 1,755 ms
363,540 KB
testcase_13 AC 1,849 ms
346,644 KB
testcase_14 AC 838 ms
326,516 KB
testcase_15 AC 839 ms
326,624 KB
testcase_16 AC 818 ms
325,960 KB
testcase_17 AC 819 ms
325,868 KB
testcase_18 AC 801 ms
325,048 KB
testcase_19 AC 833 ms
326,808 KB
testcase_20 AC 821 ms
326,028 KB
testcase_21 AC 774 ms
319,636 KB
testcase_22 AC 771 ms
319,512 KB
testcase_23 AC 774 ms
319,904 KB
testcase_24 AC 772 ms
319,892 KB
testcase_25 AC 774 ms
319,896 KB
testcase_26 AC 774 ms
319,920 KB
testcase_27 AC 776 ms
319,508 KB
testcase_28 AC 1,736 ms
341,312 KB
testcase_29 AC 1,332 ms
339,988 KB
testcase_30 AC 1,299 ms
337,020 KB
testcase_31 AC 1,950 ms
346,960 KB
testcase_32 AC 1,876 ms
346,668 KB
testcase_33 AC 891 ms
338,124 KB
testcase_34 AC 1,411 ms
340,820 KB
testcase_35 AC 771 ms
319,696 KB
testcase_36 AC 772 ms
319,644 KB
testcase_37 AC 773 ms
319,984 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) * (1 << j) % mod
        ans %= mod
ans *= pow(2, mod - 2)
ans %= mod
print(ans)
0