結果

問題 No.1843 Tree ANDistance
ユーザー ああいいああいい
提出日時 2022-02-18 22:01:43
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,028 bytes
コンパイル時間 326 ms
コンパイル使用メモリ 86,948 KB
実行使用メモリ 139,848 KB
最終ジャッジ日時 2023-09-11 19:09:29
合計ジャッジ時間 27,834 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,675 ms
102,652 KB
testcase_01 AC 1,669 ms
102,844 KB
testcase_02 AC 1,596 ms
102,652 KB
testcase_03 AC 1,645 ms
102,324 KB
testcase_04 AC 1,336 ms
102,480 KB
testcase_05 AC 919 ms
139,848 KB
testcase_06 AC 1,358 ms
134,404 KB
testcase_07 AC 1,510 ms
101,476 KB
testcase_08 AC 1,396 ms
103,432 KB
testcase_09 AC 1,470 ms
101,592 KB
testcase_10 AC 1,533 ms
101,600 KB
testcase_11 AC 1,625 ms
102,536 KB
testcase_12 AC 797 ms
138,820 KB
testcase_13 AC 1,282 ms
119,008 KB
testcase_14 AC 166 ms
78,940 KB
testcase_15 AC 169 ms
78,940 KB
testcase_16 AC 126 ms
78,356 KB
testcase_17 AC 124 ms
77,876 KB
testcase_18 AC 125 ms
77,756 KB
testcase_19 AC 138 ms
78,560 KB
testcase_20 AC 124 ms
78,588 KB
testcase_21 AC 71 ms
71,344 KB
testcase_22 AC 71 ms
71,096 KB
testcase_23 AC 71 ms
71,292 KB
testcase_24 AC 70 ms
71,216 KB
testcase_25 AC 70 ms
71,272 KB
testcase_26 AC 71 ms
71,232 KB
testcase_27 AC 71 ms
71,436 KB
testcase_28 AC 345 ms
92,620 KB
testcase_29 AC 270 ms
88,272 KB
testcase_30 WA -
testcase_31 AC 390 ms
94,264 KB
testcase_32 AC 353 ms
93,208 KB
testcase_33 WA -
testcase_34 AC 274 ms
96,620 KB
testcase_35 AC 72 ms
71,048 KB
testcase_36 AC 70 ms
71,224 KB
testcase_37 AC 72 ms
71,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
r = sys.stdin
sys.setrecursionlimit(10 ** 8)
N = int(r.readline())
_max = 0
G = [[] for _ in range(N+1)]
for _ in range(N-1):
    a,b,c = map(int,r.readline().split())
    if c > _max:
        _max = c
    G[a].append((b,c))
    G[b].append((a,c))
k = 0
while 1 << k < _max:
    k += 1
ans = 0
P = 10 ** 9 + 7
def find(i):
    if parent[i] < 0:return i
    parent[i] = find(parent[i])
    return parent[i]
def unite(i,j):
    I = find(i)
    J = find(j)
    if I == J:return False
    if parent[I] < parent[J]:
        I,J = J,I
    parent[J] += parent[I]
    parent[I] = J
    return True
for i in range(k):
    mask = 1 << i
    parent = [-1] * (N+1)
    stack = [(1,-1)]
    while stack:
        now,p = stack.pop()
        for v,c in G[now]:
            if v == p:continue
            if c & mask:
                unite(now,v)
            stack.append((v,now))
    for i in range(1,N+1):
        if parent[i] < 0:
            num = -parent[i]
            ans = (ans + num * (num-1) //2 % P * mask) % P
print(ans)
0