結果

問題 No.1098 LCAs
ユーザー roarisroaris
提出日時 2020-06-27 06:31:07
言語 PyPy3
(7.3.15)
結果
MLE  
実行時間 -
コード長 548 bytes
コンパイル時間 281 ms
コンパイル使用メモリ 87,112 KB
実行使用メモリ 838,972 KB
最終ジャッジ日時 2023-09-18 18:58:40
合計ジャッジ時間 11,913 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,312 KB
testcase_01 AC 73 ms
71,404 KB
testcase_02 AC 72 ms
71,572 KB
testcase_03 AC 72 ms
71,448 KB
testcase_04 AC 76 ms
71,132 KB
testcase_05 AC 73 ms
70,940 KB
testcase_06 AC 74 ms
71,316 KB
testcase_07 AC 73 ms
71,264 KB
testcase_08 AC 73 ms
71,056 KB
testcase_09 AC 73 ms
71,404 KB
testcase_10 AC 74 ms
71,468 KB
testcase_11 AC 73 ms
71,240 KB
testcase_12 AC 73 ms
71,420 KB
testcase_13 AC 94 ms
76,316 KB
testcase_14 AC 90 ms
75,976 KB
testcase_15 AC 94 ms
76,008 KB
testcase_16 AC 92 ms
76,468 KB
testcase_17 AC 93 ms
76,452 KB
testcase_18 AC 487 ms
103,416 KB
testcase_19 AC 481 ms
103,880 KB
testcase_20 AC 493 ms
103,848 KB
testcase_21 AC 483 ms
103,128 KB
testcase_22 AC 484 ms
103,588 KB
testcase_23 AC 373 ms
115,504 KB
testcase_24 AC 374 ms
115,308 KB
testcase_25 AC 323 ms
117,184 KB
testcase_26 AC 320 ms
114,636 KB
testcase_27 AC 322 ms
114,844 KB
testcase_28 MLE -
testcase_29 -- -
testcase_30 -- -
権限があれば一括ダウンロードができます

ソースコード

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