結果

問題 No.1098 LCAs
ユーザー H3PO4H3PO4
提出日時 2020-06-26 22:43:14
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 606 bytes
コンパイル時間 70 ms
コンパイル使用メモリ 10,948 KB
実行使用メモリ 48,468 KB
最終ジャッジ日時 2023-09-18 06:23:56
合計ジャッジ時間 10,796 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
8,252 KB
testcase_01 AC 15 ms
8,296 KB
testcase_02 AC 16 ms
8,200 KB
testcase_03 AC 17 ms
8,244 KB
testcase_04 AC 17 ms
8,212 KB
testcase_05 AC 16 ms
8,256 KB
testcase_06 AC 15 ms
8,240 KB
testcase_07 AC 15 ms
8,148 KB
testcase_08 AC 17 ms
8,252 KB
testcase_09 AC 16 ms
8,284 KB
testcase_10 AC 16 ms
8,112 KB
testcase_11 AC 16 ms
8,212 KB
testcase_12 AC 16 ms
8,244 KB
testcase_13 AC 20 ms
8,400 KB
testcase_14 AC 21 ms
8,564 KB
testcase_15 AC 21 ms
8,376 KB
testcase_16 AC 20 ms
8,480 KB
testcase_17 AC 20 ms
8,464 KB
testcase_18 AC 1,190 ms
48,440 KB
testcase_19 AC 1,189 ms
48,444 KB
testcase_20 AC 1,183 ms
48,308 KB
testcase_21 AC 1,178 ms
48,468 KB
testcase_22 AC 1,193 ms
48,364 KB
testcase_23 TLE -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import itertools
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] += 2 * S + sum(p * q for p, q in itertools.combinations(children, 2)) * 2
    return S + 1


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