結果

問題 No.1477 Lamps on Graph
ユーザー lie_of_lillielie_of_lillie
提出日時 2021-05-12 20:23:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 866 ms / 2,000 ms
コード長 771 bytes
コンパイル時間 486 ms
コンパイル使用メモリ 11,848 KB
実行使用メモリ 69,732 KB
最終ジャッジ日時 2023-10-24 15:11:53
合計ジャッジ時間 17,125 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
10,172 KB
testcase_01 AC 29 ms
10,172 KB
testcase_02 AC 29 ms
10,172 KB
testcase_03 AC 29 ms
10,172 KB
testcase_04 AC 28 ms
10,172 KB
testcase_05 AC 28 ms
10,172 KB
testcase_06 AC 29 ms
10,172 KB
testcase_07 AC 29 ms
10,172 KB
testcase_08 AC 29 ms
10,172 KB
testcase_09 AC 29 ms
10,172 KB
testcase_10 AC 28 ms
10,172 KB
testcase_11 AC 29 ms
10,172 KB
testcase_12 AC 547 ms
35,040 KB
testcase_13 AC 475 ms
35,576 KB
testcase_14 AC 633 ms
41,516 KB
testcase_15 AC 309 ms
22,648 KB
testcase_16 AC 164 ms
21,320 KB
testcase_17 AC 155 ms
21,816 KB
testcase_18 AC 455 ms
52,192 KB
testcase_19 AC 423 ms
36,884 KB
testcase_20 AC 203 ms
19,140 KB
testcase_21 AC 383 ms
46,612 KB
testcase_22 AC 163 ms
14,972 KB
testcase_23 AC 398 ms
25,060 KB
testcase_24 AC 680 ms
46,480 KB
testcase_25 AC 270 ms
21,776 KB
testcase_26 AC 618 ms
47,996 KB
testcase_27 AC 339 ms
25,620 KB
testcase_28 AC 391 ms
30,832 KB
testcase_29 AC 370 ms
28,164 KB
testcase_30 AC 232 ms
34,368 KB
testcase_31 AC 181 ms
26,884 KB
testcase_32 AC 843 ms
69,732 KB
testcase_33 AC 774 ms
58,492 KB
testcase_34 AC 661 ms
68,936 KB
testcase_35 AC 866 ms
59,108 KB
testcase_36 AC 857 ms
58,660 KB
testcase_37 AC 787 ms
52,888 KB
testcase_38 AC 833 ms
56,276 KB
testcase_39 AC 843 ms
58,500 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import collections

N, M = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))

G = collections.defaultdict(set)

for _ in range(M):
    v0, v1 = map(lambda x: int(x) - 1, input().split())
    # 計算量の削減
    if A[v0] < A[v1]:
        G[v0].add(v1)
    else:
        G[v1].add(v0)

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

onoff = [int(gi in B) for gi in range(N)]
greedy = [(A[ai], ai) for ai in range(N)]
greedy.sort()

ans = []
for a, gi in greedy:
    if onoff[gi] != 1:
        continue
    onoff[gi] = 0
    ans.append(gi)
    for ri in G[gi]:
        if A[ri] > a:
            onoff[ri] ^= 1

if sum(onoff) > 0:
    print(-1)
else:
    print(len(ans))
    print(*map(lambda x: x + 1, ans), sep='\n')
0