結果

問題 No.1098 LCAs
ユーザー uni_pythonuni_python
提出日時 2020-06-26 23:10:08
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,392 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 137,340 KB
最終ジャッジ日時 2023-09-18 07:30:46
合計ジャッジ時間 16,584 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 173 ms
80,992 KB
testcase_01 AC 178 ms
80,976 KB
testcase_02 AC 73 ms
71,432 KB
testcase_03 AC 181 ms
80,960 KB
testcase_04 AC 176 ms
80,680 KB
testcase_05 AC 176 ms
80,824 KB
testcase_06 AC 174 ms
80,796 KB
testcase_07 AC 176 ms
81,036 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 174 ms
81,016 KB
testcase_11 AC 177 ms
80,980 KB
testcase_12 AC 176 ms
80,808 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 684 ms
135,272 KB
testcase_26 AC 689 ms
137,340 KB
testcase_27 AC 684 ms
136,576 KB
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    if N==1:
        print(1)
        exit()
    
    adj=[[]for _ in range(N)]
    
    for i in range(N-1):
        v,w=MI()
        v-=1
        w-=1
        adj[v].append(w)
        adj[w].append(v)
        
    P=[-2]*N
    
    import queue
    
    # q=queue.Queue()
    # q.put(0,-1)
    
    # P[0]=0#0の親は0とする
    
    # while not q.empty():
    #     v,p=q.get()
    #     for nv in adj[v]:
    #         if P[nv]==-2:
    #             P[nv]=v
    #             q.put(nv,v)
        
    #見るやつ,まずは葉から
    q2=queue.Queue()
    used=[0]*N
    
    for i in range(1,N):
        if len(adj[i])==1:
            q2.put(i)
            used[i]=1
            
    anss=[[0,0]for _ in range(N)]#答え,部分木のサイズ
    
    while not q2.empty():
        v=q2.get()
        s=1
        temp=0#子の合計
        for nv in adj[v]:
            nvs=anss[nv][1]
            s+=nvs
            temp+=anss[nv][1]**2
            if used[nv]==0:
                q2.put(nv)
                used[nv]=1
            
        anss[v][1]=s
        anss[v][0]=s*s-temp
        
    for i in range(N):
        print(anss[i][0])
            
                


main()
0