結果

問題 No.1098 LCAs
ユーザー kohei2019kohei2019
提出日時 2022-07-25 23:49:26
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 616 bytes
コンパイル時間 288 ms
コンパイル使用メモリ 87,132 KB
実行使用メモリ 849,428 KB
最終ジャッジ日時 2023-09-22 10:46:04
合計ジャッジ時間 12,363 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,204 KB
testcase_01 AC 73 ms
71,208 KB
testcase_02 AC 70 ms
71,384 KB
testcase_03 AC 70 ms
71,424 KB
testcase_04 AC 70 ms
71,424 KB
testcase_05 AC 72 ms
71,608 KB
testcase_06 AC 71 ms
71,116 KB
testcase_07 AC 69 ms
71,488 KB
testcase_08 AC 70 ms
71,064 KB
testcase_09 AC 69 ms
71,224 KB
testcase_10 AC 70 ms
71,360 KB
testcase_11 AC 70 ms
71,364 KB
testcase_12 AC 70 ms
71,324 KB
testcase_13 AC 107 ms
78,588 KB
testcase_14 AC 102 ms
76,856 KB
testcase_15 AC 100 ms
76,860 KB
testcase_16 AC 95 ms
76,688 KB
testcase_17 AC 101 ms
76,784 KB
testcase_18 AC 626 ms
126,356 KB
testcase_19 AC 624 ms
125,908 KB
testcase_20 AC 641 ms
126,640 KB
testcase_21 AC 625 ms
126,144 KB
testcase_22 AC 649 ms
126,420 KB
testcase_23 AC 483 ms
132,140 KB
testcase_24 AC 474 ms
131,968 KB
testcase_25 AC 412 ms
132,116 KB
testcase_26 AC 418 ms
134,440 KB
testcase_27 AC 424 ms
134,568 KB
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
sys.setrecursionlimit(10**7)
N = int(input())
lsg = [[] for i in range(N)]
for i in range(N-1):
    v,w = map(int,input().split())
    v -= 1
    w -= 1
    lsg[v].append(w)
    lsg[w].append(v)

dp = [0]*(N)
dp2 = [[1] for i in range(N)]

def dfs(k,p):
    cnt = 1
    for j in lsg[k]:
        if j == p:
            continue
        c = dfs(j,k)
        dp2[k].append(c)
        cnt += c
    dp[k] = cnt
    return cnt

dfs(0,-1)

for i in range(N):
    l = dp2[i]
    if len(l) == 1:
        print(1)
        continue
    sm = sum(l)
    ans = 1
    for j in l:
        ans += j*(sm-j)
    print(ans)

0