結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー 8nd5t8nd5t
提出日時 2021-03-05 22:31:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 821 bytes
コンパイル時間 179 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 180,480 KB
最終ジャッジ日時 2024-04-16 10:17:03
合計ジャッジ時間 11,564 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 145 ms
84,852 KB
testcase_01 AC 149 ms
84,428 KB
testcase_02 AC 148 ms
84,864 KB
testcase_03 AC 342 ms
96,780 KB
testcase_04 AC 346 ms
96,844 KB
testcase_05 AC 342 ms
97,116 KB
testcase_06 AC 329 ms
96,836 KB
testcase_07 AC 346 ms
96,768 KB
testcase_08 AC 278 ms
93,016 KB
testcase_09 AC 214 ms
89,452 KB
testcase_10 AC 232 ms
89,856 KB
testcase_11 AC 202 ms
87,552 KB
testcase_12 AC 263 ms
91,724 KB
testcase_13 AC 275 ms
92,928 KB
testcase_14 AC 296 ms
93,292 KB
testcase_15 AC 248 ms
90,956 KB
testcase_16 AC 184 ms
86,272 KB
testcase_17 AC 186 ms
86,696 KB
testcase_18 AC 338 ms
96,372 KB
testcase_19 AC 204 ms
87,876 KB
testcase_20 AC 180 ms
86,272 KB
testcase_21 AC 246 ms
91,188 KB
testcase_22 AC 242 ms
90,112 KB
testcase_23 AC 179 ms
85,844 KB
testcase_24 AC 186 ms
86,272 KB
testcase_25 AC 172 ms
85,888 KB
testcase_26 AC 187 ms
86,236 KB
testcase_27 AC 153 ms
85,480 KB
testcase_28 AC 156 ms
85,124 KB
testcase_29 AC 179 ms
86,436 KB
testcase_30 AC 180 ms
86,292 KB
testcase_31 AC 171 ms
86,348 KB
testcase_32 AC 176 ms
86,640 KB
testcase_33 AC 221 ms
102,656 KB
testcase_34 AC 465 ms
180,480 KB
testcase_35 AC 276 ms
120,576 KB
testcase_36 AC 176 ms
86,528 KB
testcase_37 AC 265 ms
100,224 KB
testcase_38 AC 258 ms
98,304 KB
testcase_39 AC 143 ms
84,760 KB
testcase_40 AC 167 ms
84,724 KB
testcase_41 AC 144 ms
84,500 KB
testcase_42 AC 149 ms
84,992 KB
testcase_43 AC 149 ms
84,792 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
from bisect import bisect_left,bisect_right
import sys,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))
def err(x): print(x); exit()

n = inp()
g = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = inpl_1()
    g[b].append(a); g[a].append(b)
res = 0
def dfs(u,p=-1):
    global res
    su = 0
    for v in g[u]:
        if p==v: continue
        now = dfs(v,u)
        res += now*(n-now)
        su += now
    up = (n-su-1)
    res += up*(n-up)
    res += n
    return su+1
dfs(0)
print(res)
0