結果

問題 No.2618 除霊
ユーザー ニックネームニックネーム
提出日時 2024-01-26 23:05:39
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 889 ms / 2,000 ms
コード長 571 bytes
コンパイル時間 302 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 158,760 KB
最終ジャッジ日時 2024-01-26 23:06:11
合計ジャッジ時間 30,942 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
53,460 KB
testcase_01 AC 37 ms
53,460 KB
testcase_02 AC 36 ms
53,460 KB
testcase_03 AC 36 ms
53,460 KB
testcase_04 AC 35 ms
53,460 KB
testcase_05 AC 36 ms
53,460 KB
testcase_06 AC 731 ms
115,748 KB
testcase_07 AC 674 ms
116,124 KB
testcase_08 AC 843 ms
126,524 KB
testcase_09 AC 889 ms
136,464 KB
testcase_10 AC 830 ms
151,896 KB
testcase_11 AC 644 ms
111,896 KB
testcase_12 AC 840 ms
126,020 KB
testcase_13 AC 484 ms
111,904 KB
testcase_14 AC 591 ms
158,760 KB
testcase_15 AC 507 ms
110,872 KB
testcase_16 AC 542 ms
110,656 KB
testcase_17 AC 669 ms
133,068 KB
testcase_18 AC 636 ms
157,180 KB
testcase_19 AC 588 ms
110,796 KB
testcase_20 AC 531 ms
111,052 KB
testcase_21 AC 614 ms
129,392 KB
testcase_22 AC 662 ms
157,876 KB
testcase_23 AC 588 ms
113,036 KB
testcase_24 AC 606 ms
111,200 KB
testcase_25 AC 701 ms
131,596 KB
testcase_26 AC 652 ms
157,652 KB
testcase_27 AC 573 ms
110,936 KB
testcase_28 AC 590 ms
113,104 KB
testcase_29 AC 679 ms
131,788 KB
testcase_30 AC 743 ms
156,000 KB
testcase_31 AC 852 ms
125,640 KB
testcase_32 AC 636 ms
106,312 KB
testcase_33 AC 714 ms
107,976 KB
testcase_34 AC 778 ms
112,660 KB
testcase_35 AC 763 ms
118,320 KB
testcase_36 AC 832 ms
121,544 KB
testcase_37 AC 782 ms
126,764 KB
testcase_38 AC 885 ms
132,296 KB
testcase_39 AC 822 ms
136,008 KB
testcase_40 AC 850 ms
139,964 KB
testcase_41 AC 836 ms
147,068 KB
testcase_42 AC 825 ms
151,816 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[p]>0 for p in range(n))
for p in range(n):
    t = s-(c[p]>0)
    for v in adj[p]:
        if c[v]: t -= c[v]-(p in a)-(v in a)==0
        if v in a: t -= d[v]-(c[p]==1)
    print(t)
0