結果

問題 No.1098 LCAs
ユーザー anagohirameanagohirame
提出日時 2020-06-26 21:43:24
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 555 bytes
コンパイル時間 443 ms
コンパイル使用メモリ 87,032 KB
実行使用メモリ 849,636 KB
最終ジャッジ日時 2023-09-18 03:48:22
合計ジャッジ時間 13,085 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 AC 72 ms
71,508 KB
testcase_03 AC 72 ms
71,388 KB
testcase_04 AC 73 ms
71,504 KB
testcase_05 WA -
testcase_06 AC 71 ms
71,504 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**6)
n = int(input())
adj = [[] for _ in range(n)]
children = [[] for _ in range(n)]
ans = [0 for _ in range(n)]
for _ in range(n-1):
    u, v = map(int, input().split())
    adj[u-1].append(v-1)
    adj[v-1].append(u-1)

def dfs(x, p):
    for v in adj[x]:
        if v == p:
            continue
        dfs(v, x)
    s = sum(children[x])
    res = 2*s+1
    for i in children[x]:
        res += 2 * i * (s-i)
    if x != 0:
        children[p].append(s+1)
    ans[x] = res
    return

dfs(0, -1)
print(*ans, sep="\n")
0