結果

問題 No.1098 LCAs
ユーザー anagohirameanagohirame
提出日時 2020-06-26 21:45:24
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 551 bytes
コンパイル時間 477 ms
コンパイル使用メモリ 87,056 KB
実行使用メモリ 849,392 KB
最終ジャッジ日時 2023-09-18 03:54:53
合計ジャッジ時間 12,983 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,300 KB
testcase_01 AC 75 ms
71,200 KB
testcase_02 AC 74 ms
71,268 KB
testcase_03 AC 76 ms
71,204 KB
testcase_04 AC 72 ms
71,120 KB
testcase_05 AC 74 ms
71,232 KB
testcase_06 AC 74 ms
71,276 KB
testcase_07 AC 74 ms
71,244 KB
testcase_08 AC 74 ms
71,044 KB
testcase_09 AC 74 ms
71,252 KB
testcase_10 AC 75 ms
71,048 KB
testcase_11 AC 75 ms
71,052 KB
testcase_12 AC 76 ms
71,280 KB
testcase_13 AC 98 ms
76,540 KB
testcase_14 AC 102 ms
76,068 KB
testcase_15 AC 100 ms
76,060 KB
testcase_16 AC 104 ms
76,572 KB
testcase_17 AC 99 ms
76,000 KB
testcase_18 AC 703 ms
123,768 KB
testcase_19 AC 671 ms
123,040 KB
testcase_20 AC 685 ms
123,520 KB
testcase_21 AC 714 ms
123,276 KB
testcase_22 AC 691 ms
123,676 KB
testcase_23 AC 545 ms
127,792 KB
testcase_24 AC 557 ms
127,464 KB
testcase_25 AC 486 ms
127,112 KB
testcase_26 AC 482 ms
128,412 KB
testcase_27 AC 474 ms
128,364 KB
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 += i * (s-i)
    if x != 0:
        children[p].append(s+1)
    ans[x] = res
    return

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