結果

問題 No.2618 除霊
ユーザー rlangevinrlangevin
提出日時 2024-01-27 15:29:15
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,835 bytes
コンパイル時間 293 ms
コンパイル使用メモリ 81,572 KB
実行使用メモリ 163,188 KB
最終ジャッジ日時 2024-01-27 15:29:29
合計ジャッジ時間 13,715 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
60,264 KB
testcase_01 AC 34 ms
53,460 KB
testcase_02 AC 33 ms
53,460 KB
testcase_03 AC 38 ms
53,460 KB
testcase_04 AC 44 ms
59,336 KB
testcase_05 AC 34 ms
53,460 KB
testcase_06 AC 577 ms
114,716 KB
testcase_07 AC 625 ms
114,580 KB
testcase_08 AC 756 ms
130,620 KB
testcase_09 AC 863 ms
142,868 KB
testcase_10 AC 873 ms
163,188 KB
testcase_11 AC 497 ms
109,240 KB
testcase_12 AC 768 ms
128,704 KB
testcase_13 TLE -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
testcase_40 -- -
testcase_41 -- -
testcase_42 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = sys.stdin.readline

class Fenwick_Tree:
    def __init__(self, n):
        self._n = n
        self.data = [0] * n

    def add(self, p, x):
        assert 0 <= p < self._n
        p += 1
        while p <= self._n:
            self.data[p - 1] += x
            p += p & -p

    def sum(self, l, r):
        assert 0 <= l <= r <= self._n
        return self._sum(r) - self._sum(l)

    def _sum(self, r):
        s = 0
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get_size(self, x):
        x = self.find(x)
        while r > 0:
            s += self.data[r - 1]
            r -= r & -r
        return s

    def get(self, k):
        k += 1
        x, r = 0, 1
        while r < self._n:
            r <<= 1
        len = r
        while len:
            if x + len - 1 < self._n:
                if self.data[x + len - 1] < k:
                    k -= self.data[x + len - 1]
                    x += len
            len >>= 1
        return x


N = int(input())
G = [[] for i in range(N)]
for i in range(N - 1):
    u, v = map(int, input().split())
    u, v = u - 1, v - 1
    G[u].append(v)
    G[v].append(u)
    
M = int(input())
V = list(map(int, input().split()))
for i in range(M):
    V[i] -= 1
for i in range(N):
    G[i].append(i)
V = set(V)

T = Fenwick_Tree(N)
cnt = [0] * N
for i in V:
    for u in G[i]:
        cnt[u] += 1
        if cnt[u] == 1:
            T.add(u, 1)
            
for i in range(N):
    for u in G[i]:
        if u in V:
            for v in G[u]:
                cnt[v] -= 1
                if cnt[v] == 0:
                    T.add(v, -1)
    print(T.sum(0, N))
    for u in G[i]:
        if u in V:
            for v in G[u]:
                cnt[v] += 1
                if cnt[v] == 1:
                    T.add(v, 1)
0