結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー minatominato
提出日時 2023-03-09 07:44:18
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 428 bytes
コンパイル時間 316 ms
コンパイル使用メモリ 81,656 KB
実行使用メモリ 90,808 KB
最終ジャッジ日時 2023-10-18 06:12:34
合計ジャッジ時間 9,728 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,416 KB
testcase_01 AC 38 ms
53,416 KB
testcase_02 AC 37 ms
53,416 KB
testcase_03 AC 260 ms
87,664 KB
testcase_04 AC 272 ms
88,020 KB
testcase_05 AC 286 ms
88,120 KB
testcase_06 AC 271 ms
87,748 KB
testcase_07 AC 266 ms
87,760 KB
testcase_08 AC 213 ms
84,168 KB
testcase_09 AC 135 ms
79,868 KB
testcase_10 AC 147 ms
80,364 KB
testcase_11 AC 113 ms
78,464 KB
testcase_12 AC 180 ms
82,504 KB
testcase_13 AC 192 ms
83,512 KB
testcase_14 AC 209 ms
84,128 KB
testcase_15 AC 175 ms
82,188 KB
testcase_16 AC 93 ms
76,756 KB
testcase_17 AC 94 ms
76,920 KB
testcase_18 AC 263 ms
86,848 KB
testcase_19 AC 113 ms
78,252 KB
testcase_20 AC 90 ms
76,672 KB
testcase_21 AC 173 ms
82,168 KB
testcase_22 AC 154 ms
81,084 KB
testcase_23 AC 83 ms
76,360 KB
testcase_24 AC 89 ms
76,864 KB
testcase_25 AC 82 ms
76,284 KB
testcase_26 AC 85 ms
76,508 KB
testcase_27 AC 50 ms
61,604 KB
testcase_28 AC 58 ms
65,728 KB
testcase_29 AC 90 ms
76,612 KB
testcase_30 AC 92 ms
76,740 KB
testcase_31 AC 75 ms
73,884 KB
testcase_32 AC 83 ms
76,480 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 86 ms
77,100 KB
testcase_37 AC 192 ms
89,300 KB
testcase_38 AC 175 ms
87,768 KB
testcase_39 AC 38 ms
53,432 KB
testcase_40 AC 36 ms
53,432 KB
testcase_41 AC 38 ms
53,432 KB
testcase_42 AC 38 ms
53,432 KB
testcase_43 AC 37 ms
53,432 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for _ in range(N)]
for _ in range(N - 1):
    a, b = map(int, input().split())
    G[a - 1].append(b - 1)
    G[b - 1].append(a - 1)

ans = 0


def dfs(v, pv):
    global ans
    cnt = 1
    for nv in G[v]:
        if nv == pv:
            continue
        chi = dfs(nv, v)
        ans += (N - chi) * chi
        cnt += chi
    ans += cnt * (N - cnt)
    ans += N
    return cnt


dfs(0, -1)
print(ans)
0