結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー NatsubiSoganNatsubiSogan
提出日時 2021-03-06 17:10:06
言語 Python3
(3.11.6 + numpy 1.26.0 + scipy 1.11.3)
結果
AC  
実行時間 510 ms / 2,000 ms
コード長 442 bytes
コンパイル時間 244 ms
コンパイル使用メモリ 10,936 KB
実行使用メモリ 43,976 KB
最終ジャッジ日時 2023-07-30 03:34:21
合計ジャッジ時間 9,250 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,808 KB
testcase_01 AC 16 ms
7,788 KB
testcase_02 AC 15 ms
7,940 KB
testcase_03 AC 483 ms
24,952 KB
testcase_04 AC 459 ms
24,936 KB
testcase_05 AC 465 ms
24,932 KB
testcase_06 AC 474 ms
24,912 KB
testcase_07 AC 475 ms
24,860 KB
testcase_08 AC 307 ms
19,372 KB
testcase_09 AC 142 ms
13,628 KB
testcase_10 AC 155 ms
14,100 KB
testcase_11 AC 91 ms
11,296 KB
testcase_12 AC 242 ms
17,144 KB
testcase_13 AC 301 ms
18,812 KB
testcase_14 AC 315 ms
19,292 KB
testcase_15 AC 231 ms
16,412 KB
testcase_16 AC 38 ms
9,216 KB
testcase_17 AC 40 ms
9,176 KB
testcase_18 AC 441 ms
23,456 KB
testcase_19 AC 86 ms
11,060 KB
testcase_20 AC 26 ms
8,580 KB
testcase_21 AC 217 ms
16,276 KB
testcase_22 AC 192 ms
15,184 KB
testcase_23 AC 28 ms
8,476 KB
testcase_24 AC 28 ms
8,476 KB
testcase_25 AC 24 ms
8,480 KB
testcase_26 AC 29 ms
8,632 KB
testcase_27 AC 17 ms
7,836 KB
testcase_28 AC 19 ms
8,256 KB
testcase_29 AC 34 ms
8,912 KB
testcase_30 AC 30 ms
8,748 KB
testcase_31 AC 23 ms
8,324 KB
testcase_32 AC 26 ms
8,632 KB
testcase_33 AC 109 ms
16,284 KB
testcase_34 AC 510 ms
43,976 KB
testcase_35 AC 202 ms
23,316 KB
testcase_36 AC 58 ms
9,872 KB
testcase_37 AC 369 ms
21,460 KB
testcase_38 AC 341 ms
20,296 KB
testcase_39 AC 15 ms
7,880 KB
testcase_40 AC 15 ms
7,824 KB
testcase_41 AC 16 ms
7,824 KB
testcase_42 AC 16 ms
7,776 KB
testcase_43 AC 15 ms
7,900 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