結果

問題 No.1098 LCAs
ユーザー chineristACchineristAC
提出日時 2020-06-26 22:25:18
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
RE  
実行時間 -
コード長 455 bytes
コンパイル時間 175 ms
コンパイル使用メモリ 10,964 KB
実行使用メモリ 46,108 KB
最終ジャッジ日時 2023-09-18 05:46:45
合計ジャッジ時間 12,721 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 15 ms
7,960 KB
testcase_01 AC 15 ms
7,836 KB
testcase_02 AC 16 ms
7,988 KB
testcase_03 AC 17 ms
7,844 KB
testcase_04 AC 16 ms
7,860 KB
testcase_05 AC 17 ms
7,844 KB
testcase_06 AC 15 ms
7,988 KB
testcase_07 AC 16 ms
7,860 KB
testcase_08 AC 16 ms
7,804 KB
testcase_09 AC 16 ms
7,844 KB
testcase_10 AC 15 ms
7,852 KB
testcase_11 AC 15 ms
7,904 KB
testcase_12 AC 16 ms
7,888 KB
testcase_13 AC 19 ms
8,340 KB
testcase_14 AC 18 ms
8,360 KB
testcase_15 AC 19 ms
8,236 KB
testcase_16 AC 20 ms
8,268 KB
testcase_17 AC 18 ms
8,280 KB
testcase_18 AC 876 ms
45,264 KB
testcase_19 AC 884 ms
45,184 KB
testcase_20 AC 862 ms
45,188 KB
testcase_21 AC 882 ms
45,124 KB
testcase_22 AC 864 ms
45,140 KB
testcase_23 AC 717 ms
40,212 KB
testcase_24 AC 717 ms
40,212 KB
testcase_25 AC 677 ms
39,828 KB
testcase_26 AC 754 ms
46,108 KB
testcase_27 AC 739 ms
45,928 KB
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

input=sys.stdin.readline

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