結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー 👑 hitonanodehitonanode
提出日時 2021-02-06 12:58:05
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 623 bytes
コンパイル時間 356 ms
コンパイル使用メモリ 10,824 KB
実行使用メモリ 25,000 KB
最終ジャッジ日時 2023-09-15 19:05:37
合計ジャッジ時間 6,393 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,800 KB
testcase_01 AC 16 ms
7,808 KB
testcase_02 AC 16 ms
7,864 KB
testcase_03 AC 293 ms
24,956 KB
testcase_04 AC 290 ms
24,924 KB
testcase_05 AC 291 ms
25,000 KB
testcase_06 AC 288 ms
24,840 KB
testcase_07 AC 283 ms
24,964 KB
testcase_08 AC 183 ms
19,468 KB
testcase_09 AC 83 ms
13,508 KB
testcase_10 AC 91 ms
14,120 KB
testcase_11 AC 61 ms
11,388 KB
testcase_12 AC 136 ms
17,144 KB
testcase_13 AC 160 ms
18,844 KB
testcase_14 AC 173 ms
19,356 KB
testcase_15 AC 130 ms
16,392 KB
testcase_16 AC 28 ms
9,176 KB
testcase_17 AC 27 ms
9,192 KB
testcase_18 AC 245 ms
23,448 KB
testcase_19 AC 48 ms
11,040 KB
testcase_20 AC 21 ms
8,624 KB
testcase_21 AC 149 ms
16,276 KB
testcase_22 AC 102 ms
15,120 KB
testcase_23 AC 21 ms
8,496 KB
testcase_24 AC 22 ms
8,700 KB
testcase_25 AC 19 ms
8,544 KB
testcase_26 AC 21 ms
8,704 KB
testcase_27 AC 16 ms
7,832 KB
testcase_28 AC 17 ms
8,228 KB
testcase_29 AC 24 ms
9,064 KB
testcase_30 AC 23 ms
8,824 KB
testcase_31 AC 19 ms
8,228 KB
testcase_32 AC 21 ms
8,560 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 35 ms
9,940 KB
testcase_37 AC 179 ms
21,548 KB
testcase_38 AC 168 ms
20,236 KB
testcase_39 AC 16 ms
7,940 KB
testcase_40 AC 15 ms
7,908 KB
testcase_41 AC 15 ms
7,904 KB
testcase_42 AC 15 ms
7,948 KB
testcase_43 AC 16 ms
7,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

ret = 0

def main():
    N = int(input())
    to = [[] for _ in range(N)]

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


    def dfs(now: int, prv: int) -> int:
        global ret
        nexts = to[now]
        subtree_size = 1
        for nxt in nexts:
            if nxt != prv:
                tmp = dfs(nxt, now)
                ret += tmp * (N - tmp) * 2
                subtree_size += tmp
        ret += N
        return subtree_size

    dfs(0, -1)
    print(ret)


main()
0