結果

問題 No.872 All Tree Path
ユーザー ningenMeningenMe
提出日時 2019-08-29 23:10:52
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 474 bytes
コンパイル時間 141 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 135,644 KB
最終ジャッジ日時 2024-04-28 21:20:25
合計ジャッジ時間 8,478 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 810 ms
132,608 KB
testcase_01 AC 802 ms
133,252 KB
testcase_02 AC 999 ms
134,044 KB
testcase_03 RE -
testcase_04 AC 37 ms
52,336 KB
testcase_05 AC 828 ms
132,940 KB
testcase_06 AC 834 ms
133,552 KB
testcase_07 AC 820 ms
133,000 KB
testcase_08 AC 146 ms
82,604 KB
testcase_09 AC 153 ms
82,400 KB
testcase_10 AC 146 ms
82,208 KB
testcase_11 AC 154 ms
82,432 KB
testcase_12 AC 150 ms
82,560 KB
testcase_13 AC 37 ms
51,840 KB
testcase_14 AC 37 ms
52,352 KB
testcase_15 AC 38 ms
52,096 KB
testcase_16 AC 38 ms
52,224 KB
testcase_17 AC 38 ms
52,352 KB
testcase_18 AC 38 ms
52,224 KB
testcase_19 AC 37 ms
51,840 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
edge = [[] for i in range(N)]
size = [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])

def dfs(f,p):
    for t,w in edge[f]:
        if t == p:
            continue
        dfs(t,f)
    if p != -1:
        size[p] += size[f]

dfs(0,-1)
ans = 0
for i in range(N):
    for j,w in edge[i]:
        M = min(size[i],size[j])
        ans += M*(N-M)*w
print(ans)
0