結果

問題 No.2618 除霊
ユーザー titiatitia
提出日時 2024-01-29 01:32:47
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,037 bytes
コンパイル時間 330 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 424,804 KB
最終ジャッジ日時 2024-01-29 01:33:01
合計ジャッジ時間 13,740 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 35 ms
60,264 KB
testcase_01 AC 35 ms
53,460 KB
testcase_02 AC 39 ms
53,460 KB
testcase_03 AC 35 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 39 ms
53,460 KB
testcase_06 AC 859 ms
161,176 KB
testcase_07 AC 730 ms
160,584 KB
testcase_08 AC 1,057 ms
182,160 KB
testcase_09 AC 1,151 ms
195,528 KB
testcase_10 AC 1,300 ms
207,796 KB
testcase_11 AC 597 ms
156,488 KB
testcase_12 AC 994 ms
181,864 KB
testcase_13 AC 450 ms
167,592 KB
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):
    if len(A)==0:
        return set()
    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