結果

問題 No.1098 LCAs
ユーザー stngstng
提出日時 2022-08-29 20:29:29
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 588 bytes
コンパイル時間 167 ms
コンパイル使用メモリ 82,164 KB
実行使用メモリ 114,276 KB
最終ジャッジ日時 2024-04-24 10:27:39
合計ジャッジ時間 10,058 ms
ジャッジサーバーID
(参考情報)
judge1 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
52,224 KB
testcase_01 AC 42 ms
52,224 KB
testcase_02 AC 38 ms
52,224 KB
testcase_03 AC 39 ms
52,608 KB
testcase_04 AC 39 ms
52,096 KB
testcase_05 AC 40 ms
51,840 KB
testcase_06 AC 39 ms
51,840 KB
testcase_07 AC 38 ms
52,224 KB
testcase_08 AC 40 ms
51,968 KB
testcase_09 AC 39 ms
51,968 KB
testcase_10 AC 40 ms
51,968 KB
testcase_11 AC 40 ms
51,968 KB
testcase_12 AC 39 ms
52,352 KB
testcase_13 AC 67 ms
69,504 KB
testcase_14 AC 67 ms
69,632 KB
testcase_15 AC 69 ms
68,992 KB
testcase_16 AC 62 ms
66,176 KB
testcase_17 AC 67 ms
69,504 KB
testcase_18 AC 589 ms
111,616 KB
testcase_19 AC 587 ms
112,000 KB
testcase_20 AC 593 ms
111,868 KB
testcase_21 AC 598 ms
111,616 KB
testcase_22 AC 594 ms
112,128 KB
testcase_23 AC 487 ms
114,276 KB
testcase_24 AC 486 ms
114,160 KB
testcase_25 AC 431 ms
113,720 KB
testcase_26 AC 432 ms
113,676 KB
testcase_27 AC 434 ms
113,652 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
vw = [[] for i in range(n)]

for i in range(n-1):
    v,w = map(int,input().split())
    v -= 1
    w -= 1
    vw[v].append(w)
    vw[w].append(v)

dp = [0]*n
chk = [0]*n
ans = [0]*n

def dfs(v,pre):
    if chk[v] == 1:
        return dp[v]
    tmp = 1
    rui2 = 0
    for i in range(len(vw[v])):
        if vw[v][i] == pre:
            continue
        t = dfs(vw[v][i],v)
        dp[v] += t
        tmp += t
        rui2 += t**2
        chk[v] = 1
    dp[v] += 1
    ans[v] = tmp**2-rui2
    return dp[v]

dfs(0,-1)
#print(dp)
print(*ans,sep="\n")
#for i in range(n):
0