結果

問題 No.2618 除霊
ユーザー nikoro256nikoro256
提出日時 2024-01-26 23:13:50
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 789 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 168,408 KB
最終ジャッジ日時 2024-01-26 23:14:28
合計ジャッジ時間 25,159 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 38 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 38 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 601 ms
117,528 KB
testcase_07 AC 541 ms
117,392 KB
testcase_08 AC 694 ms
132,152 KB
testcase_09 AC 711 ms
144,400 KB
testcase_10 AC 715 ms
163,268 KB
testcase_11 AC 481 ms
112,068 KB
testcase_12 AC 660 ms
131,380 KB
testcase_13 AC 363 ms
109,900 KB
testcase_14 AC 489 ms
168,408 KB
testcase_15 AC 355 ms
107,372 KB
testcase_16 AC 404 ms
107,508 KB
testcase_17 AC 490 ms
136,788 KB
testcase_18 AC 509 ms
167,252 KB
testcase_19 AC 385 ms
107,836 KB
testcase_20 AC 360 ms
107,400 KB
testcase_21 AC 451 ms
137,824 KB
testcase_22 AC 505 ms
167,980 KB
testcase_23 AC 426 ms
112,508 KB
testcase_24 AC 475 ms
110,664 KB
testcase_25 AC 531 ms
135,912 KB
testcase_26 AC 570 ms
166,944 KB
testcase_27 AC 409 ms
110,588 KB
testcase_28 AC 470 ms
111,352 KB
testcase_29 AC 538 ms
135,872 KB
testcase_30 AC 609 ms
143,428 KB
testcase_31 AC 648 ms
131,644 KB
testcase_32 AC 470 ms
104,524 KB
testcase_33 AC 509 ms
108,364 KB
testcase_34 AC 568 ms
113,032 KB
testcase_35 AC 572 ms
121,252 KB
testcase_36 AC 671 ms
126,028 KB
testcase_37 AC 615 ms
131,616 KB
testcase_38 AC 721 ms
139,852 KB
testcase_39 AC 665 ms
144,460 KB
testcase_40 AC 713 ms
149,668 KB
testcase_41 AC 789 ms
156,684 KB
testcase_42 AC 731 ms
163,208 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input=sys.stdin.readline
N=int(input())
edge=[[] for _ in range(N)]
for _ in range(N-1):
    a,b=map(int,input().split())
    edge[a-1].append(b-1)
    edge[b-1].append(a-1)
M=int(input())
count=[False]*N
vtoinfect=[0]*(N)
V=list(map(int,input().split()))
V=set(V)
for v in V:
    count[v-1]+=1
    for e in edge[v-1]:
        count[e]+=1
for v in V:
    for e in edge[v-1]:
        if count[e]==1:
            vtoinfect[v-1]+=1
ans_one=N-count.count(0)
is_obake=[int(i+1 in V) for i in range(N)]
for i in range(N):
    sub=0
    if count[i]>0:
        sub+=1
    for e in edge[i]:
        if count[e]>0 and count[e]-is_obake[i]-is_obake[e]==0:
            sub+=1
        if is_obake[e]==1:
            sub+=vtoinfect[e]-int(count[i]==1)
    print(ans_one-sub)
0