結果

問題 No.2618 除霊
ユーザー ニックネームニックネーム
提出日時 2024-01-26 22:56:00
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
WA  
実行時間 -
コード長 562 bytes
コンパイル時間 136 ms
コンパイル使用メモリ 11,904 KB
実行使用メモリ 75,812 KB
最終ジャッジ日時 2024-01-26 22:57:11
合計ジャッジ時間 65,532 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 28 ms
10,112 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 1,985 ms
74,600 KB
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 AC 1,829 ms
75,648 KB
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 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
testcase_40 WA -
testcase_41 WA -
testcase_42 AC 1,961 ms
74,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n-1):
    a,b = map(int,input().split())
    adj[a-1].append(b-1); adj[b-1].append(a-1)
m = int(input())
a = {v-1 for v in map(int,input().split())}
c = [0]*n; d = [0]*n
for p in range(n):
    c[p] = p in a
    for v in adj[p]: c[p] += v in a
for p in range(n):
    if p in a:
        for v in adj[p]: d[p] += c[v]==1
s = sum(c[i]>0 for i in range(n))
for p in range(n):
    t = s-(c[p]>0)
    for v in adj[p]:
        t -= c[v]-(p in a)-(v in a)==0
        if v in a: t -= d[v]-(c[p]==1)
    print(t)
0