結果

問題 No.1477 Lamps on Graph
ユーザー brthyyjpbrthyyjp
提出日時 2021-08-30 20:19:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 465 ms / 2,000 ms
コード長 798 bytes
コンパイル時間 308 ms
コンパイル使用メモリ 82,688 KB
実行使用メモリ 116,824 KB
最終ジャッジ日時 2024-05-03 05:46:08
合計ジャッジ時間 11,718 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,352 KB
testcase_01 AC 43 ms
52,352 KB
testcase_02 AC 45 ms
52,736 KB
testcase_03 AC 43 ms
52,608 KB
testcase_04 AC 42 ms
52,352 KB
testcase_05 AC 44 ms
52,608 KB
testcase_06 AC 43 ms
52,736 KB
testcase_07 AC 43 ms
52,608 KB
testcase_08 AC 43 ms
52,992 KB
testcase_09 AC 43 ms
52,864 KB
testcase_10 AC 43 ms
52,608 KB
testcase_11 AC 44 ms
52,352 KB
testcase_12 AC 285 ms
87,680 KB
testcase_13 AC 323 ms
91,304 KB
testcase_14 AC 309 ms
89,692 KB
testcase_15 AC 194 ms
81,580 KB
testcase_16 AC 171 ms
83,384 KB
testcase_17 AC 188 ms
83,036 KB
testcase_18 AC 307 ms
101,496 KB
testcase_19 AC 288 ms
89,856 KB
testcase_20 AC 207 ms
81,100 KB
testcase_21 AC 310 ms
100,364 KB
testcase_22 AC 165 ms
78,816 KB
testcase_23 AC 234 ms
82,596 KB
testcase_24 AC 412 ms
94,956 KB
testcase_25 AC 217 ms
81,832 KB
testcase_26 AC 338 ms
97,268 KB
testcase_27 AC 205 ms
83,308 KB
testcase_28 AC 224 ms
86,912 KB
testcase_29 AC 262 ms
84,352 KB
testcase_30 AC 217 ms
91,136 KB
testcase_31 AC 205 ms
84,768 KB
testcase_32 AC 465 ms
116,824 KB
testcase_33 AC 450 ms
113,432 KB
testcase_34 AC 245 ms
100,172 KB
testcase_35 AC 438 ms
106,520 KB
testcase_36 AC 407 ms
102,396 KB
testcase_37 AC 301 ms
99,072 KB
testcase_38 AC 359 ms
99,328 KB
testcase_39 AC 407 ms
102,752 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
g = [[] for i in range(n)]
for i in range(m):
    u, v = map(int, input().split())
    u, v = u-1, v-1
    if A[u] < A[v]:
        g[u].append(v)
    elif A[u] > A[v]:
        g[v].append(u)
k = int(input())
B = list(map(int, input().split()))
B = [b-1 for b in B]
C = [0]*n
for b in B:
    C[b] = 1

q = []
import heapq
for b in B:
    q.append((A[b], b))
heapq.heapify(q)
ans = []
while q:
    a, v =heapq.heappop(q)
    if C[v] == 0:
        continue
    C[v] = 0
    ans.append(v+1)
    for u in g[v]:
        C[u] = 1-C[u]
        heapq.heappush(q, (A[u], u))
if sum(C) > 0:
    print(-1)
    exit()
print(len(ans))
print(*ans, sep='\n')
0