結果

問題 No.1477 Lamps on Graph
ユーザー c-yanc-yan
提出日時 2021-04-16 22:58:06
言語 PyPy3
(7.3.15)
結果
RE  
実行時間 -
コード長 1,562 bytes
コンパイル時間 301 ms
コンパイル使用メモリ 87,212 KB
実行使用メモリ 281,304 KB
最終ジャッジ日時 2023-09-16 02:12:58
合計ジャッジ時間 12,057 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,564 KB
testcase_01 AC 73 ms
71,072 KB
testcase_02 AC 77 ms
71,636 KB
testcase_03 AC 74 ms
71,068 KB
testcase_04 AC 72 ms
71,336 KB
testcase_05 RE -
testcase_06 RE -
testcase_07 AC 74 ms
71,296 KB
testcase_08 RE -
testcase_09 AC 74 ms
71,620 KB
testcase_10 RE -
testcase_11 AC 74 ms
71,100 KB
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 WA -
testcase_16 RE -
testcase_17 WA -
testcase_18 RE -
testcase_19 WA -
testcase_20 WA -
testcase_21 TLE -
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 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import setrecursionlimit, stdin


def find(parent, i):
    t = parent[i]
    if t < 0:
        return i
    t = find(parent, t)
    parent[i] = t
    return t


def unite(parent, i, j):
    i = find(parent, i)
    j = find(parent, j)
    if i == j:
        return
    parent[j] += parent[i]
    parent[i] = j


def bit_add(bit, i, x):
    i += 1
    n = len(bit)
    while i <= n:
        bit[i - 1] += x
        i += i & -i


def bit_sum(bit, i):
    result = 0
    i += 1
    while i > 0:
        result += bit[i - 1]
        i -= i & -i
    return result


def query(bit, start, stop):
    if start == 0:
        return bit_sum(bit, stop - 1)
    else:
        return bit_sum(bit, stop - 1) - bit_sum(bit, start - 1)


readline = stdin.readline
setrecursionlimit(10 ** 6)

N, M = map(int, readline().split())
A = list(map(int, readline().split()))

a = sorted(set(A))
t = {}
for i in range(N):
    t[a[i]] = i
for i in range(N):
    A[i] = t[A[i]]

parent = [-1] * N
for _ in range(M):
    u, v = map(lambda x: int(x) - 1, readline().split())
    unite(parent, u, v)

K = int(readline())
B = set(map(lambda x: int(x) - 1, readline().split()))

t = {}
for i in range(N):
    p = find(parent, i)
    t.setdefault(p, [])
    t[p].append((A[i], i))
for k in t:
    t[k] = sorted(t[k])

result = []
for k in t:
    bit = [0] * (N + 1)
    for a, i in t[k]:
        x = query(bit, 0, a)
        if i in B:
            x += 1
        if x % 2 == 1:
            result.append(i + 1)
            bit_add(bit, a, 1)
print(len(result))
print(*result, sep='\n')
0