結果

問題 No.1098 LCAs
ユーザー convexineqconvexineq
提出日時 2020-06-26 21:43:53
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,139 ms / 2,000 ms
コード長 659 bytes
コンパイル時間 74 ms
コンパイル使用メモリ 10,764 KB
実行使用メモリ 72,448 KB
最終ジャッジ日時 2023-09-18 03:50:05
合計ジャッジ時間 14,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 17 ms
7,804 KB
testcase_01 AC 16 ms
7,784 KB
testcase_02 AC 16 ms
7,928 KB
testcase_03 AC 16 ms
7,792 KB
testcase_04 AC 16 ms
7,952 KB
testcase_05 AC 16 ms
8,004 KB
testcase_06 AC 16 ms
7,844 KB
testcase_07 AC 17 ms
7,868 KB
testcase_08 AC 16 ms
7,804 KB
testcase_09 AC 16 ms
7,792 KB
testcase_10 AC 16 ms
7,908 KB
testcase_11 AC 16 ms
7,864 KB
testcase_12 AC 16 ms
7,812 KB
testcase_13 AC 19 ms
8,480 KB
testcase_14 AC 18 ms
8,480 KB
testcase_15 AC 19 ms
8,476 KB
testcase_16 AC 19 ms
8,480 KB
testcase_17 AC 18 ms
8,460 KB
testcase_18 AC 1,003 ms
67,404 KB
testcase_19 AC 1,003 ms
67,256 KB
testcase_20 AC 989 ms
67,020 KB
testcase_21 AC 1,001 ms
67,132 KB
testcase_22 AC 996 ms
67,376 KB
testcase_23 AC 834 ms
57,924 KB
testcase_24 AC 834 ms
57,748 KB
testcase_25 AC 777 ms
55,388 KB
testcase_26 AC 829 ms
67,948 KB
testcase_27 AC 840 ms
67,888 KB
testcase_28 AC 1,138 ms
72,396 KB
testcase_29 AC 1,139 ms
72,448 KB
testcase_30 AC 1,119 ms
72,328 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,*vw = map(int,read().split())
m = iter(vw)

g = [[] for _ in range(n)]
for v,w in zip(m,m):
    g[v-1].append(w-1)
    g[w-1].append(v-1)


order = []
parent = [-1]*n

st = [0]
while st:
    v = st.pop()
    order.append(v)
    for c in g[v]:
        if c != parent[v]:
            parent[c] = v
            st.append(c)

res = [1]*n
for i in order[:0:-1]:
    res[parent[i]] += res[i]
for i in range(n):
    res[i] *= res[i]

for i in order[1:]:
    res[parent[i]] -= res[i]
    
print(*res,sep="\n")
            
        
        
        
        
        
0