結果

問題 No.1098 LCAs
ユーザー titiatitia
提出日時 2020-06-26 23:15:40
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 595 ms / 2,000 ms
コード長 727 bytes
コンパイル時間 956 ms
コンパイル使用メモリ 86,468 KB
実行使用メモリ 153,780 KB
最終ジャッジ日時 2023-09-18 07:48:02
合計ジャッジ時間 10,282 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
70,876 KB
testcase_01 AC 71 ms
70,916 KB
testcase_02 AC 70 ms
70,864 KB
testcase_03 AC 70 ms
70,864 KB
testcase_04 AC 70 ms
71,124 KB
testcase_05 AC 69 ms
71,120 KB
testcase_06 AC 72 ms
70,880 KB
testcase_07 AC 71 ms
70,856 KB
testcase_08 AC 69 ms
70,960 KB
testcase_09 AC 69 ms
70,764 KB
testcase_10 AC 70 ms
70,912 KB
testcase_11 AC 71 ms
71,124 KB
testcase_12 AC 70 ms
70,884 KB
testcase_13 AC 109 ms
77,748 KB
testcase_14 AC 108 ms
77,548 KB
testcase_15 AC 103 ms
76,356 KB
testcase_16 AC 102 ms
76,140 KB
testcase_17 AC 105 ms
77,512 KB
testcase_18 AC 527 ms
120,320 KB
testcase_19 AC 508 ms
120,280 KB
testcase_20 AC 526 ms
120,040 KB
testcase_21 AC 509 ms
120,028 KB
testcase_22 AC 533 ms
119,992 KB
testcase_23 AC 519 ms
149,152 KB
testcase_24 AC 556 ms
149,556 KB
testcase_25 AC 439 ms
153,780 KB
testcase_26 AC 440 ms
140,292 KB
testcase_27 AC 435 ms
139,672 KB
testcase_28 AC 529 ms
119,740 KB
testcase_29 AC 566 ms
119,840 KB
testcase_30 AC 595 ms
119,516 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N=int(input())
E=[[] for i in range(N+1)]


for i in range(N-1):
    x,y=map(int,input().split())
    E[x].append(y)
    E[y].append(x)

Q=[1]
TOP_SORT=[]
USE=[0]*(N+1)
USE[1]=1
P=[-1]*(N+1)
while Q:
    x=Q.pop()
    TOP_SORT.append(x)
    for to in E[x]:
        if USE[to]==0:
            USE[to]=1
            Q.append(to)
            P[to]=x

Children=[1]*(N+1)

for t in TOP_SORT[::-1]:

    if t!=1 and len(E[t])==1:
        Children[t]=1

    if t!=1:
        Children[P[t]]+=Children[t]

for i in range(1,N+1):
    ANS=Children[i]*2-1

    X=[]
    for to in E[i]:
        if to==P[i]:
            continue
        X.append(Children[to])

    S=sum(X)

    for x in X:
        ANS+=x*(S-x)

    print(ANS)

    
    

0