結果

問題 No.2618 除霊
ユーザー mkawa2mkawa2
提出日時 2024-01-26 23:13:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 676 ms / 2,000 ms
コード長 1,328 bytes
コンパイル時間 165 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 148,884 KB
最終ジャッジ日時 2024-01-26 23:13:36
合計ジャッジ時間 24,923 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 37 ms
53,460 KB
testcase_03 AC 37 ms
53,460 KB
testcase_04 AC 37 ms
53,460 KB
testcase_05 AC 38 ms
53,460 KB
testcase_06 AC 582 ms
110,268 KB
testcase_07 AC 534 ms
110,124 KB
testcase_08 AC 629 ms
121,468 KB
testcase_09 AC 601 ms
120,752 KB
testcase_10 AC 643 ms
140,148 KB
testcase_11 AC 484 ms
110,452 KB
testcase_12 AC 627 ms
120,468 KB
testcase_13 AC 372 ms
114,056 KB
testcase_14 AC 471 ms
140,664 KB
testcase_15 AC 391 ms
113,468 KB
testcase_16 AC 415 ms
112,096 KB
testcase_17 AC 501 ms
130,340 KB
testcase_18 AC 482 ms
138,100 KB
testcase_19 AC 442 ms
113,248 KB
testcase_20 AC 397 ms
114,176 KB
testcase_21 AC 451 ms
124,444 KB
testcase_22 AC 531 ms
148,884 KB
testcase_23 AC 434 ms
114,572 KB
testcase_24 AC 468 ms
112,728 KB
testcase_25 AC 510 ms
126,812 KB
testcase_26 AC 531 ms
139,696 KB
testcase_27 AC 436 ms
113,372 KB
testcase_28 AC 435 ms
114,468 KB
testcase_29 AC 506 ms
129,000 KB
testcase_30 AC 534 ms
141,708 KB
testcase_31 AC 642 ms
121,124 KB
testcase_32 AC 505 ms
106,148 KB
testcase_33 AC 552 ms
107,428 KB
testcase_34 AC 555 ms
108,188 KB
testcase_35 AC 561 ms
110,292 KB
testcase_36 AC 613 ms
116,516 KB
testcase_37 AC 593 ms
115,812 KB
testcase_38 AC 656 ms
123,172 KB
testcase_39 AC 616 ms
125,732 KB
testcase_40 AC 628 ms
131,236 KB
testcase_41 AC 676 ms
131,620 KB
testcase_42 AC 639 ms
140,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

n = II()
to = [[] for _ in range(n)]
deg = [0]*n
for _ in range(n-1):
    u, v = LI1()
    to[u].append(v)
    to[v].append(u)
    deg[u] += 1
    deg[v] += 1
m = II()
vv=LI1()

go = [0]*n
tr = [0]*n
for v in vv:
    go[v] = 1
    tr[v]+=1
    for u in to[v]:
        tr[u]+=1

one=[0]*n
for u in vv:
    for v in to[u]:
        one[u]+=tr[v]==1
# pDB(tr)
# pDB(one)

tot=n-tr.count(0)
for u in range(n):
    ans=tot-one[u]
    for v in to[u]:
        ans-=one[v]
        if go[v] and tr[v]-go[u]-go[v]==0:ans-=1
    if go[u] or tr[u]>1:ans-=1
    print(ans)

0