結果

問題 No.2618 除霊
ユーザー titiatitia
提出日時 2024-01-29 01:30:44
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 998 bytes
コンパイル時間 287 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 424,804 KB
最終ジャッジ日時 2024-01-29 01:30:58
合計ジャッジ時間 12,851 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 RE -
testcase_03 RE -
testcase_04 AC 38 ms
53,460 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 AC 1,392 ms
207,792 KB
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 TLE -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

N=int(input())
E=[set() for i in range(N)]

for i in range(N-1):
    a,b=map(int,input().split())
    a-=1
    b-=1
    E[a].add(b)
    E[b].add(a)

ANS=[0]*N

M=int(input())
V=list(map(int,input().split()))

for i in range(M):
    V[i]-=1
BLIST=[0]*N
for v in V:
    BLIST[v]=1

for v in V:
    ANS[v]+=1
    for to in E[v]:
        ANS[to]+=1

SUM=0
for a in ANS:
    if a>=1:
        SUM+=1


def neighbor(A):
    S=E[A[0]]|{A[0]}
    for i in range(1,len(A)):
        S=S&(E[A[i]]|{A[i]})
    return S

ANSLIST=[SUM]*N
DICT=dict()
for i in range(N):
    LIST=[]
    if BLIST[i]==1:
        LIST.append(i)
        
    for to in E[i]:
        if BLIST[to]==1:
            LIST.append(to)

    LIST.sort()

    if tuple(LIST) in DICT:
        DICT[tuple(LIST)].append(i)
    else:
        DICT[tuple(LIST)]=[i]

for d in DICT:
    S=neighbor(d)

    #print(d,S,DICT[d])

    for a in S:
        ANSLIST[a]-=len(DICT[d])


print("\n".join(map(str,ANSLIST)))
0