結果

問題 No.1098 LCAs
ユーザー H3PO4H3PO4
提出日時 2020-06-27 08:54:38
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,771 ms / 2,000 ms
コード長 562 bytes
コンパイル時間 304 ms
コンパイル使用メモリ 10,984 KB
実行使用メモリ 94,012 KB
最終ジャッジ日時 2023-09-18 19:03:58
合計ジャッジ時間 18,394 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,888 KB
testcase_01 AC 16 ms
7,708 KB
testcase_02 AC 16 ms
7,936 KB
testcase_03 AC 15 ms
7,892 KB
testcase_04 AC 16 ms
7,808 KB
testcase_05 AC 16 ms
7,792 KB
testcase_06 AC 15 ms
7,748 KB
testcase_07 AC 16 ms
7,832 KB
testcase_08 AC 16 ms
7,792 KB
testcase_09 AC 16 ms
7,784 KB
testcase_10 AC 16 ms
7,780 KB
testcase_11 AC 15 ms
7,888 KB
testcase_12 AC 16 ms
7,936 KB
testcase_13 AC 20 ms
8,380 KB
testcase_14 AC 21 ms
8,520 KB
testcase_15 AC 21 ms
8,480 KB
testcase_16 AC 20 ms
8,476 KB
testcase_17 AC 20 ms
8,376 KB
testcase_18 AC 1,155 ms
48,308 KB
testcase_19 AC 1,169 ms
48,416 KB
testcase_20 AC 1,160 ms
48,312 KB
testcase_21 AC 1,163 ms
48,444 KB
testcase_22 AC 1,180 ms
48,364 KB
testcase_23 AC 953 ms
43,236 KB
testcase_24 AC 967 ms
43,296 KB
testcase_25 AC 927 ms
42,892 KB
testcase_26 AC 978 ms
49,124 KB
testcase_27 AC 989 ms
49,208 KB
testcase_28 AC 1,703 ms
89,824 KB
testcase_29 AC 1,731 ms
94,012 KB
testcase_30 AC 1,771 ms
90,184 KB
権限があれば一括ダウンロードができます

ソースコード

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