結果

問題 No.1098 LCAs
ユーザー H3PO4H3PO4
提出日時 2020-06-27 08:56:08
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 562 bytes
コンパイル時間 695 ms
コンパイル使用メモリ 87,108 KB
実行使用メモリ 913,284 KB
最終ジャッジ日時 2023-09-18 19:05:07
合計ジャッジ時間 12,905 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 75 ms
71,488 KB
testcase_02 AC 75 ms
71,384 KB
testcase_03 AC 76 ms
71,328 KB
testcase_04 AC 77 ms
71,256 KB
testcase_05 AC 76 ms
71,420 KB
testcase_06 AC 76 ms
71,332 KB
testcase_07 AC 76 ms
71,124 KB
testcase_08 AC 77 ms
71,384 KB
testcase_09 AC 77 ms
71,248 KB
testcase_10 AC 78 ms
71,052 KB
testcase_11 AC 78 ms
71,256 KB
testcase_12 AC 76 ms
71,324 KB
testcase_13 AC 104 ms
76,272 KB
testcase_14 AC 106 ms
76,456 KB
testcase_15 AC 103 ms
76,324 KB
testcase_16 AC 109 ms
77,796 KB
testcase_17 AC 106 ms
76,708 KB
testcase_18 AC 601 ms
111,916 KB
testcase_19 AC 642 ms
111,604 KB
testcase_20 AC 592 ms
111,720 KB
testcase_21 AC 599 ms
111,132 KB
testcase_22 AC 607 ms
111,856 KB
testcase_23 AC 465 ms
118,356 KB
testcase_24 AC 437 ms
116,860 KB
testcase_25 AC 381 ms
126,024 KB
testcase_26 AC 445 ms
126,072 KB
testcase_27 AC 376 ms
126,080 KB
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 9)
int1 = lambda x: int(x) - 1

N = int(input())
T = [[] for _ in range(N)]
for _ in range(N - 1):
    v, w = map(int1, input().split())
    T[v].append(w)
    T[w].append(v)

ans = [1] * N


def rec(child, parent):
    if len(T[child]) <= 1 and parent >= 0:
        return 1

    children = []
    for c in T[child]:
        if c != parent:
            children.append(rec(c, child))

    S = sum(children)
    ans[child] = (S + 1) ** 2 - sum(x ** 2 for x in children)
    return S + 1


rec(0, -1)
print(*ans, sep='\n')
0