結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-03-06 17:10:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 410 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 81,920 KB
実行使用メモリ 177,280 KB
最終ジャッジ日時 2024-04-17 05:39:08
合計ジャッジ時間 8,188 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 39 ms
51,712 KB
testcase_01 AC 41 ms
51,968 KB
testcase_02 AC 41 ms
51,968 KB
testcase_03 AC 240 ms
88,448 KB
testcase_04 AC 257 ms
88,576 KB
testcase_05 AC 267 ms
88,320 KB
testcase_06 AC 266 ms
88,064 KB
testcase_07 AC 258 ms
88,064 KB
testcase_08 AC 202 ms
84,608 KB
testcase_09 AC 138 ms
80,384 KB
testcase_10 AC 152 ms
81,152 KB
testcase_11 AC 125 ms
78,976 KB
testcase_12 AC 181 ms
82,816 KB
testcase_13 AC 190 ms
84,096 KB
testcase_14 AC 194 ms
84,608 KB
testcase_15 AC 180 ms
82,304 KB
testcase_16 AC 107 ms
76,928 KB
testcase_17 AC 109 ms
77,184 KB
testcase_18 AC 260 ms
87,168 KB
testcase_19 AC 126 ms
78,592 KB
testcase_20 AC 101 ms
77,184 KB
testcase_21 AC 173 ms
82,304 KB
testcase_22 AC 165 ms
81,024 KB
testcase_23 AC 99 ms
76,800 KB
testcase_24 AC 105 ms
77,056 KB
testcase_25 AC 97 ms
76,544 KB
testcase_26 AC 100 ms
76,928 KB
testcase_27 AC 56 ms
60,544 KB
testcase_28 AC 67 ms
64,768 KB
testcase_29 AC 103 ms
77,056 KB
testcase_30 AC 106 ms
76,928 KB
testcase_31 AC 90 ms
73,984 KB
testcase_32 AC 96 ms
76,416 KB
testcase_33 AC 136 ms
92,544 KB
testcase_34 AC 410 ms
177,280 KB
testcase_35 AC 193 ms
108,928 KB
testcase_36 AC 99 ms
77,440 KB
testcase_37 AC 202 ms
89,984 KB
testcase_38 AC 171 ms
88,960 KB
testcase_39 AC 41 ms
51,968 KB
testcase_40 AC 42 ms
51,968 KB
testcase_41 AC 41 ms
51,968 KB
testcase_42 AC 41 ms
51,840 KB
testcase_43 AC 42 ms
51,968 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 6)
n = int(input())
G = [[] for i 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(now, prev):
    global ans
    res = 1
    for nex in G[now]:
        if nex == prev: continue
        tmp = dfs(nex, now)
        ans += tmp * (n - tmp) * 2
        res += tmp
    ans += n
    return res
dfs(0, -1)
print(ans)
0