結果

問題 No.872 All Tree Path
ユーザー ningenMeningenMe
提出日時 2019-08-30 01:13:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,431 ms / 3,000 ms
コード長 615 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,048 KB
実行使用メモリ 177,064 KB
最終ジャッジ日時 2024-04-28 23:06:20
合計ジャッジ時間 13,705 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1,417 ms
176,092 KB
testcase_01 AC 1,431 ms
176,040 KB
testcase_02 AC 1,426 ms
175,656 KB
testcase_03 AC 688 ms
174,708 KB
testcase_04 AC 65 ms
66,816 KB
testcase_05 AC 1,399 ms
175,916 KB
testcase_06 AC 1,363 ms
175,452 KB
testcase_07 AC 1,367 ms
177,064 KB
testcase_08 AC 249 ms
87,728 KB
testcase_09 AC 244 ms
88,044 KB
testcase_10 AC 245 ms
87,760 KB
testcase_11 AC 249 ms
88,064 KB
testcase_12 AC 246 ms
88,448 KB
testcase_13 AC 64 ms
67,584 KB
testcase_14 AC 64 ms
67,072 KB
testcase_15 AC 66 ms
67,200 KB
testcase_16 AC 65 ms
67,456 KB
testcase_17 AC 66 ms
67,328 KB
testcase_18 AC 65 ms
67,328 KB
testcase_19 AC 68 ms
67,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import queue
N = int(input())
edge = [[] for i in range(N)]
size = [1 for i in range(N)]
parent = [[-1,-1] for i in range(N)]

for i in range(N-1):
    u,v,w = map(int,input().split())
    u-=1
    v-=1
    edge[u].append([v,w])
    edge[v].append([u,w])

q = queue.Queue()
s = queue.LifoQueue()
parent[0] = [0,0]
q.put(0)
while q.qsize() > 0:
    f = q.get()
    for t,w in edge[f]:
        if parent[t][0] == -1:
            parent[t] = [f,w]
            q.put(t)
    s.put(f)
ans = 0
while s.qsize() > 0:
    f = s.get()
    size[parent[f][0]] += size[f]
    ans += size[f]*(N-size[f])*parent[f][1]*2
print(ans)
0