結果

問題 No.1477 Lamps on Graph
ユーザー nephrologistnephrologist
提出日時 2021-04-16 20:32:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,105 bytes
コンパイル時間 1,514 ms
コンパイル使用メモリ 86,960 KB
実行使用メモリ 844,136 KB
最終ジャッジ日時 2023-09-15 21:24:46
合計ジャッジ時間 12,635 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 96 ms
71,728 KB
testcase_01 AC 96 ms
71,888 KB
testcase_02 AC 99 ms
71,356 KB
testcase_03 AC 95 ms
71,808 KB
testcase_04 AC 96 ms
71,812 KB
testcase_05 AC 95 ms
71,608 KB
testcase_06 AC 96 ms
71,812 KB
testcase_07 AC 99 ms
71,336 KB
testcase_08 AC 97 ms
71,520 KB
testcase_09 WA -
testcase_10 AC 98 ms
71,564 KB
testcase_11 AC 94 ms
71,608 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 AC 161 ms
95,128 KB
testcase_31 WA -
testcase_32 MLE -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
from collections import deque

input = sys.stdin.buffer.readline

n, m = map(int, input().split())
A = list(map(int, input().split()))
graph = [[] for _ in range(n)]
deg = [0] * n
for _ in range(m):
    a, b = map(int, input().split())
    a, b = a - 1, b - 1
    if A[b] > A[a]:
        graph[a].append(b)
        deg[b] += 1
    if A[a] > A[b]:
        graph[b].append(a)
        deg[a] += 1
k = int(input())
B = list(map(int, input().split()))


finished = [0] * n
lamp = [0] * n
for b in B:
    lamp[b - 1] = 1

start = deque()

for i in range(n):
    if deg[i] == 0:
        start.append(i)

ans = []

while start:
    v = start.popleft()
    finished[v] = 1
    if lamp[v] == 0:
        for u in graph[v]:
            if finished[u]:
                continue
            start.append(u)
    else:
        ans.append(v + 1)
        lamp[v] = 0
        finished[v] = 1
        for u in graph[v]:
            lamp[u] ^= 1
            if finished[u]:
                continue
            start.append(u)

if sum(lamp) > 0:
    print(-1)
    exit()

print(len(ans))
for a in ans:
    print(a)
0