結果

問題 No.1098 LCAs
ユーザー kohei2019kohei2019
提出日時 2022-07-25 23:48:42
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 575 bytes
コンパイル時間 376 ms
コンパイル使用メモリ 87,188 KB
実行使用メモリ 133,136 KB
最終ジャッジ日時 2023-09-22 10:44:11
合計ジャッジ時間 14,338 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 83 ms
71,284 KB
testcase_01 AC 82 ms
71,012 KB
testcase_02 AC 81 ms
71,504 KB
testcase_03 AC 83 ms
71,508 KB
testcase_04 AC 82 ms
71,284 KB
testcase_05 AC 82 ms
71,404 KB
testcase_06 AC 81 ms
71,400 KB
testcase_07 AC 83 ms
70,996 KB
testcase_08 AC 83 ms
71,308 KB
testcase_09 AC 82 ms
71,340 KB
testcase_10 AC 82 ms
71,208 KB
testcase_11 AC 81 ms
71,348 KB
testcase_12 AC 82 ms
71,260 KB
testcase_13 AC 123 ms
78,308 KB
testcase_14 AC 116 ms
76,620 KB
testcase_15 AC 114 ms
76,584 KB
testcase_16 AC 111 ms
76,680 KB
testcase_17 AC 116 ms
76,668 KB
testcase_18 AC 787 ms
126,176 KB
testcase_19 AC 786 ms
125,628 KB
testcase_20 AC 779 ms
126,544 KB
testcase_21 AC 780 ms
125,808 KB
testcase_22 AC 780 ms
126,180 KB
testcase_23 AC 569 ms
132,112 KB
testcase_24 AC 570 ms
132,200 KB
testcase_25 AC 485 ms
131,876 KB
testcase_26 AC 497 ms
131,208 KB
testcase_27 AC 493 ms
133,136 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

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