結果

問題 No.1098 LCAs
ユーザー chineristACchineristAC
提出日時 2020-06-26 22:26:24
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 486 bytes
コンパイル時間 336 ms
コンパイル使用メモリ 87,300 KB
実行使用メモリ 848,976 KB
最終ジャッジ日時 2023-09-18 05:49:10
合計ジャッジ時間 10,638 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 74 ms
71,328 KB
testcase_01 AC 74 ms
71,440 KB
testcase_02 AC 72 ms
71,544 KB
testcase_03 AC 72 ms
71,328 KB
testcase_04 AC 72 ms
71,496 KB
testcase_05 AC 72 ms
71,444 KB
testcase_06 AC 73 ms
71,468 KB
testcase_07 AC 73 ms
71,432 KB
testcase_08 AC 73 ms
71,300 KB
testcase_09 AC 74 ms
71,344 KB
testcase_10 AC 72 ms
71,340 KB
testcase_11 AC 73 ms
71,372 KB
testcase_12 AC 74 ms
71,384 KB
testcase_13 AC 89 ms
76,456 KB
testcase_14 AC 88 ms
76,396 KB
testcase_15 AC 89 ms
75,996 KB
testcase_16 AC 85 ms
75,692 KB
testcase_17 AC 88 ms
76,432 KB
testcase_18 AC 461 ms
105,712 KB
testcase_19 AC 469 ms
105,060 KB
testcase_20 AC 468 ms
105,028 KB
testcase_21 AC 462 ms
104,780 KB
testcase_22 AC 475 ms
104,936 KB
testcase_23 AC 366 ms
108,016 KB
testcase_24 AC 372 ms
108,024 KB
testcase_25 AC 333 ms
108,812 KB
testcase_26 AC 342 ms
108,336 KB
testcase_27 AC 337 ms
108,828 KB
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input=sys.stdin.readline
sys.setrecursionlimit(2*10**5)

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

size=[0]*N
ans=[0]*N

def dfs(v,pv):
    size[v]=1
    res=0
    for nv in edge[v]:
        if nv!=pv:
            dfs(nv,v)
            size[v]+=size[nv]
            res-=size[nv]**2
    res+=size[v]**2
    ans[v]=res

dfs(0,-1)
for i in range(N):
    print(ans[i])
0