結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー 👑 rin204rin204
提出日時 2022-02-24 21:39:31
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 498 ms / 2,000 ms
コード長 576 bytes
コンパイル時間 607 ms
コンパイル使用メモリ 86,876 KB
実行使用メモリ 180,736 KB
最終ジャッジ日時 2023-09-15 09:57:37
合計ジャッジ時間 10,025 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,108 KB
testcase_01 AC 72 ms
71,024 KB
testcase_02 AC 71 ms
71,240 KB
testcase_03 AC 328 ms
89,412 KB
testcase_04 AC 323 ms
89,612 KB
testcase_05 AC 309 ms
89,664 KB
testcase_06 AC 322 ms
89,660 KB
testcase_07 AC 327 ms
89,944 KB
testcase_08 AC 237 ms
85,640 KB
testcase_09 AC 164 ms
81,256 KB
testcase_10 AC 172 ms
81,520 KB
testcase_11 AC 145 ms
79,488 KB
testcase_12 AC 211 ms
83,856 KB
testcase_13 AC 232 ms
84,988 KB
testcase_14 AC 239 ms
85,416 KB
testcase_15 AC 206 ms
83,816 KB
testcase_16 AC 119 ms
78,292 KB
testcase_17 AC 122 ms
78,032 KB
testcase_18 AC 312 ms
88,452 KB
testcase_19 AC 155 ms
79,692 KB
testcase_20 AC 127 ms
77,468 KB
testcase_21 AC 210 ms
83,308 KB
testcase_22 AC 181 ms
82,420 KB
testcase_23 AC 116 ms
77,632 KB
testcase_24 AC 119 ms
77,864 KB
testcase_25 AC 114 ms
77,968 KB
testcase_26 AC 114 ms
77,832 KB
testcase_27 AC 83 ms
75,884 KB
testcase_28 AC 91 ms
76,224 KB
testcase_29 AC 116 ms
77,740 KB
testcase_30 AC 111 ms
77,520 KB
testcase_31 AC 109 ms
77,592 KB
testcase_32 AC 112 ms
77,404 KB
testcase_33 AC 172 ms
96,100 KB
testcase_34 AC 498 ms
180,736 KB
testcase_35 AC 257 ms
120,088 KB
testcase_36 AC 116 ms
78,772 KB
testcase_37 AC 257 ms
93,924 KB
testcase_38 AC 251 ms
92,328 KB
testcase_39 AC 76 ms
71,320 KB
testcase_40 AC 77 ms
71,104 KB
testcase_41 AC 72 ms
71,344 KB
testcase_42 AC 71 ms
71,128 KB
testcase_43 AC 71 ms
70,928 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10 ** 9)
import pypyjit
pypyjit.set_param('max_unroll_recursion=-1')

n = int(input())
edges = [[] for _ in range(n)]
for _ in range(n - 1):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    edges[u].append(v)
    edges[v].append(u)

size = [1] * n
ans = n * n
def dfs(pos, bpos):
    global ans
    for npos in edges[pos]:
        if npos == bpos:
            continue
        dfs(npos, pos)
        size[pos] += size[npos]
        ans += size[npos] * (n - size[npos])
    ans += size[pos] * (n - size[pos])
dfs(0, -1)
print(ans)
0