結果

問題 No.1098 LCAs
ユーザー roarisroaris
提出日時 2020-06-27 06:31:51
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,401 ms / 2,000 ms
コード長 548 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 10,872 KB
実行使用メモリ 95,576 KB
最終ジャッジ日時 2023-09-18 18:59:06
合計ジャッジ時間 14,942 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 16 ms
7,724 KB
testcase_01 AC 16 ms
7,948 KB
testcase_02 AC 16 ms
7,832 KB
testcase_03 AC 16 ms
7,748 KB
testcase_04 AC 16 ms
7,832 KB
testcase_05 AC 16 ms
7,780 KB
testcase_06 AC 16 ms
7,796 KB
testcase_07 AC 16 ms
7,908 KB
testcase_08 AC 16 ms
7,752 KB
testcase_09 AC 16 ms
7,844 KB
testcase_10 AC 16 ms
7,796 KB
testcase_11 AC 16 ms
7,784 KB
testcase_12 AC 16 ms
7,736 KB
testcase_13 AC 19 ms
8,316 KB
testcase_14 AC 19 ms
8,268 KB
testcase_15 AC 19 ms
8,176 KB
testcase_16 AC 19 ms
8,332 KB
testcase_17 AC 19 ms
8,160 KB
testcase_18 AC 935 ms
43,532 KB
testcase_19 AC 928 ms
43,608 KB
testcase_20 AC 900 ms
43,644 KB
testcase_21 AC 911 ms
43,552 KB
testcase_22 AC 914 ms
43,512 KB
testcase_23 AC 762 ms
39,880 KB
testcase_24 AC 748 ms
39,916 KB
testcase_25 AC 719 ms
39,400 KB
testcase_26 AC 772 ms
45,816 KB
testcase_27 AC 769 ms
45,740 KB
testcase_28 AC 1,361 ms
91,244 KB
testcase_29 AC 1,401 ms
95,576 KB
testcase_30 AC 1,355 ms
91,572 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

def dfs(v, pv):
    l = []
    
    for nv in G[v]:
        if nv==pv:
            continue
        
        l.append(dfs(nv, v))
    
    s = sum(l)
    
    for li in l:
        ans[v] += li*(s-li)
    
    for li in l:
        ans[v] += 2*li
    
    return s+1

N = int(input())
G = [[] for _ in range(N)]

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

ans = [1]*N
dfs(0, -1)

for ans_i in ans:
    print(ans_i)
0