結果

問題 No.1098 LCAs
ユーザー H3PO4H3PO4
提出日時 2020-06-27 08:55:17
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 562 bytes
コンパイル時間 1,220 ms
コンパイル使用メモリ 86,640 KB
実行使用メモリ 843,212 KB
最終ジャッジ日時 2023-09-18 19:04:32
合計ジャッジ時間 17,265 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,288 KB
testcase_01 AC 74 ms
71,024 KB
testcase_02 AC 75 ms
71,192 KB
testcase_03 AC 75 ms
71,184 KB
testcase_04 AC 74 ms
70,936 KB
testcase_05 AC 75 ms
71,244 KB
testcase_06 AC 75 ms
71,072 KB
testcase_07 AC 73 ms
71,264 KB
testcase_08 AC 74 ms
70,932 KB
testcase_09 AC 74 ms
70,936 KB
testcase_10 AC 74 ms
71,124 KB
testcase_11 AC 74 ms
71,336 KB
testcase_12 AC 75 ms
71,120 KB
testcase_13 AC 101 ms
76,164 KB
testcase_14 AC 104 ms
76,284 KB
testcase_15 AC 100 ms
76,128 KB
testcase_16 AC 111 ms
77,396 KB
testcase_17 AC 106 ms
76,368 KB
testcase_18 AC 612 ms
111,500 KB
testcase_19 AC 622 ms
111,348 KB
testcase_20 AC 613 ms
111,332 KB
testcase_21 AC 610 ms
110,780 KB
testcase_22 AC 608 ms
111,696 KB
testcase_23 AC 431 ms
118,072 KB
testcase_24 AC 426 ms
116,580 KB
testcase_25 AC 373 ms
125,740 KB
testcase_26 AC 367 ms
126,004 KB
testcase_27 AC 363 ms
125,964 KB
testcase_28 TLE -
testcase_29 TLE -
testcase_30 MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

sys.setrecursionlimit(10 ** 6)
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