結果

問題 No.2618 除霊
ユーザー titiatitia
提出日時 2024-02-04 03:19:10
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 1,125 ms / 2,000 ms
コード長 1,091 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 65,236 KB
最終ジャッジ日時 2024-02-04 03:19:54
合計ジャッジ時間 42,405 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
9,856 KB
testcase_01 AC 30 ms
9,856 KB
testcase_02 AC 28 ms
9,856 KB
testcase_03 AC 27 ms
9,856 KB
testcase_04 AC 28 ms
9,856 KB
testcase_05 AC 28 ms
9,856 KB
testcase_06 AC 1,063 ms
55,032 KB
testcase_07 AC 990 ms
54,828 KB
testcase_08 AC 1,089 ms
57,660 KB
testcase_09 AC 1,055 ms
58,180 KB
testcase_10 AC 1,067 ms
64,228 KB
testcase_11 AC 876 ms
54,100 KB
testcase_12 AC 1,063 ms
57,508 KB
testcase_13 AC 949 ms
54,912 KB
testcase_14 AC 984 ms
65,236 KB
testcase_15 AC 759 ms
54,272 KB
testcase_16 AC 789 ms
54,272 KB
testcase_17 AC 901 ms
59,468 KB
testcase_18 AC 957 ms
63,352 KB
testcase_19 AC 807 ms
55,680 KB
testcase_20 AC 776 ms
54,656 KB
testcase_21 AC 888 ms
57,548 KB
testcase_22 AC 964 ms
59,748 KB
testcase_23 AC 1,002 ms
55,680 KB
testcase_24 AC 974 ms
54,912 KB
testcase_25 AC 1,071 ms
60,580 KB
testcase_26 AC 1,025 ms
63,176 KB
testcase_27 AC 932 ms
54,784 KB
testcase_28 AC 993 ms
55,680 KB
testcase_29 AC 1,046 ms
59,384 KB
testcase_30 AC 995 ms
65,204 KB
testcase_31 AC 1,125 ms
57,772 KB
testcase_32 AC 915 ms
54,528 KB
testcase_33 AC 973 ms
55,168 KB
testcase_34 AC 989 ms
53,944 KB
testcase_35 AC 1,038 ms
55,780 KB
testcase_36 AC 1,102 ms
58,024 KB
testcase_37 AC 1,072 ms
56,824 KB
testcase_38 AC 1,116 ms
59,716 KB
testcase_39 AC 1,107 ms
59,748 KB
testcase_40 AC 1,085 ms
59,872 KB
testcase_41 AC 1,105 ms
63,060 KB
testcase_42 AC 1,065 ms
64,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

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

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

ANS=0

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

for i in range(M):
    V[i]-=1

LIST=[0]*N
for v in V:
    LIST[v]=1

ANS=0
ANSLIST=[0]*N
X=[0]*N

for i in range(N):
    ji=0
    if LIST[i]==1:
        ji=1
        
    U=[]
    for to in E[i]:
        if LIST[to]==1:
            U.append(to)

    if ji==0 and U==[]:
        continue
    
    ANS+=1

    if ji==1:
        ANSLIST[i]-=1
        
        if U==[]:
            for to in E[i]:
                ANSLIST[to]-=1
                
        elif len(U)==1:
            k=U[0]
            ANSLIST[k]-=1

    else:
        if len(U)>=2:
            ANSLIST[i]-=1
        else:
            k=U[0]
            X[k]+=1

for i in range(N):
    if X[i]>0:
        ANSLIST[i]-=X[i]
        for to in E[i]:
            ANSLIST[to]-=X[i]

#print(ANS)
#print(ANSLIST)

for i in range(N):
    ANSLIST[i]+=ANS

for ans in ANSLIST:
    print(ans)
0