結果

問題 No.1418 Sum of Sum of Subtree Size
ユーザー 8nd5t8nd5t
提出日時 2021-03-05 22:31:19
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 915 bytes
コンパイル時間 254 ms
コンパイル使用メモリ 82,432 KB
実行使用メモリ 91,776 KB
最終ジャッジ日時 2024-04-16 10:16:07
合計ジャッジ時間 8,136 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 53 ms
61,056 KB
testcase_01 AC 54 ms
61,056 KB
testcase_02 AC 53 ms
60,928 KB
testcase_03 AC 286 ms
89,344 KB
testcase_04 AC 298 ms
89,472 KB
testcase_05 AC 296 ms
89,984 KB
testcase_06 AC 283 ms
89,396 KB
testcase_07 AC 282 ms
88,944 KB
testcase_08 AC 227 ms
85,760 KB
testcase_09 AC 149 ms
81,280 KB
testcase_10 AC 166 ms
82,048 KB
testcase_11 AC 127 ms
79,904 KB
testcase_12 AC 199 ms
84,156 KB
testcase_13 AC 207 ms
85,248 KB
testcase_14 AC 222 ms
85,632 KB
testcase_15 AC 191 ms
83,556 KB
testcase_16 AC 103 ms
78,076 KB
testcase_17 AC 103 ms
78,148 KB
testcase_18 AC 273 ms
88,192 KB
testcase_19 AC 124 ms
79,744 KB
testcase_20 AC 94 ms
78,080 KB
testcase_21 AC 189 ms
83,328 KB
testcase_22 AC 173 ms
82,560 KB
testcase_23 AC 92 ms
77,696 KB
testcase_24 AC 98 ms
77,824 KB
testcase_25 AC 90 ms
77,440 KB
testcase_26 AC 95 ms
77,696 KB
testcase_27 AC 61 ms
64,256 KB
testcase_28 AC 68 ms
68,736 KB
testcase_29 AC 98 ms
78,080 KB
testcase_30 AC 102 ms
77,696 KB
testcase_31 AC 90 ms
77,312 KB
testcase_32 AC 91 ms
77,568 KB
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 AC 89 ms
78,068 KB
testcase_37 AC 206 ms
91,148 KB
testcase_38 AC 194 ms
89,708 KB
testcase_39 AC 54 ms
61,184 KB
testcase_40 AC 55 ms
61,184 KB
testcase_41 AC 53 ms
60,928 KB
testcase_42 AC 53 ms
61,440 KB
testcase_43 AC 54 ms
60,672 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys,math,itertools
from collections import Counter,deque,defaultdict
from bisect import bisect_left,bisect_right 
from heapq import heappop,heappush,heapify, nlargest
from copy import deepcopy
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 inps(): return sys.stdin.readline()
def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])
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