結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー ああいいああいい
提出日時 2022-01-08 20:27:19
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 568 ms / 2,000 ms
コード長 470 bytes
コンパイル時間 185 ms
コンパイル使用メモリ 82,056 KB
実行使用メモリ 231,808 KB
最終ジャッジ日時 2024-04-26 19:29:27
合計ジャッジ時間 9,180 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
52,224 KB
testcase_01 AC 37 ms
52,224 KB
testcase_02 AC 38 ms
52,340 KB
testcase_03 AC 288 ms
88,164 KB
testcase_04 AC 276 ms
88,960 KB
testcase_05 AC 290 ms
88,616 KB
testcase_06 AC 290 ms
88,960 KB
testcase_07 AC 279 ms
89,000 KB
testcase_08 AC 226 ms
85,280 KB
testcase_09 AC 148 ms
81,152 KB
testcase_10 AC 162 ms
81,504 KB
testcase_11 AC 115 ms
78,976 KB
testcase_12 AC 206 ms
83,828 KB
testcase_13 AC 198 ms
84,480 KB
testcase_14 AC 220 ms
84,836 KB
testcase_15 AC 187 ms
82,688 KB
testcase_16 AC 107 ms
77,696 KB
testcase_17 AC 131 ms
78,132 KB
testcase_18 AC 274 ms
87,804 KB
testcase_19 AC 124 ms
78,976 KB
testcase_20 AC 99 ms
77,464 KB
testcase_21 AC 188 ms
83,200 KB
testcase_22 AC 189 ms
82,432 KB
testcase_23 AC 98 ms
77,056 KB
testcase_24 AC 105 ms
77,312 KB
testcase_25 AC 97 ms
76,928 KB
testcase_26 AC 112 ms
77,964 KB
testcase_27 AC 51 ms
62,208 KB
testcase_28 AC 62 ms
68,608 KB
testcase_29 AC 107 ms
77,952 KB
testcase_30 AC 107 ms
77,056 KB
testcase_31 AC 89 ms
76,800 KB
testcase_32 AC 100 ms
77,184 KB
testcase_33 AC 180 ms
110,208 KB
testcase_34 AC 568 ms
231,808 KB
testcase_35 AC 271 ms
140,800 KB
testcase_36 AC 83 ms
77,568 KB
testcase_37 AC 182 ms
92,128 KB
testcase_38 AC 175 ms
90,840 KB
testcase_39 AC 35 ms
52,224 KB
testcase_40 AC 34 ms
52,224 KB
testcase_41 AC 35 ms
52,608 KB
testcase_42 AC 36 ms
52,480 KB
testcase_43 AC 37 ms
52,224 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N = int(input())
G = [[] for _ in range(N+1)]

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

import sys
sys.setrecursionlimit(10 ** 6)
ans = 0
def dfs(now = 1,parent = 0):
    global ans
    l = []
    for v in G[now]:
        if v == parent:continue
        l.append(dfs(v,now))
    a = N - sum(l) - 1
    ans += a * (N - a)
    for k in l:
        ans += k * (N - k)
    ans += N
    return sum(l) + 1
dfs()
print(ans)
0