結果

問題 No.1477 Lamps on Graph
ユーザー vwxyzvwxyz
提出日時 2023-11-23 05:46:22
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 488 ms / 2,000 ms
コード長 1,412 bytes
コンパイル時間 247 ms
コンパイル使用メモリ 12,032 KB
実行使用メモリ 34,444 KB
最終ジャッジ日時 2023-11-23 05:46:35
合計ジャッジ時間 10,547 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
11,136 KB
testcase_01 AC 41 ms
11,136 KB
testcase_02 AC 37 ms
11,136 KB
testcase_03 AC 36 ms
11,264 KB
testcase_04 AC 36 ms
11,264 KB
testcase_05 AC 35 ms
11,136 KB
testcase_06 AC 35 ms
11,136 KB
testcase_07 AC 35 ms
11,136 KB
testcase_08 AC 35 ms
11,136 KB
testcase_09 AC 36 ms
11,136 KB
testcase_10 AC 35 ms
11,136 KB
testcase_11 AC 35 ms
11,136 KB
testcase_12 AC 287 ms
23,264 KB
testcase_13 AC 244 ms
22,920 KB
testcase_14 AC 311 ms
24,912 KB
testcase_15 AC 162 ms
16,756 KB
testcase_16 AC 110 ms
18,288 KB
testcase_17 AC 108 ms
17,652 KB
testcase_18 AC 297 ms
28,832 KB
testcase_19 AC 223 ms
23,984 KB
testcase_20 AC 116 ms
14,976 KB
testcase_21 AC 259 ms
26,284 KB
testcase_22 AC 97 ms
13,184 KB
testcase_23 AC 229 ms
17,740 KB
testcase_24 AC 342 ms
27,988 KB
testcase_25 AC 147 ms
16,248 KB
testcase_26 AC 308 ms
28,848 KB
testcase_27 AC 177 ms
18,364 KB
testcase_28 AC 197 ms
22,204 KB
testcase_29 AC 203 ms
19,548 KB
testcase_30 AC 153 ms
20,476 KB
testcase_31 AC 119 ms
18,292 KB
testcase_32 AC 488 ms
34,292 KB
testcase_33 AC 434 ms
34,420 KB
testcase_34 AC 392 ms
31,108 KB
testcase_35 AC 472 ms
34,392 KB
testcase_36 AC 433 ms
34,444 KB
testcase_37 AC 406 ms
34,420 KB
testcase_38 AC 398 ms
34,396 KB
testcase_39 AC 430 ms
34,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import bisect
import copy
import decimal
import fractions
import heapq
import itertools
import math
import random
import sys
import time
from collections import Counter,deque,defaultdict
from functools import lru_cache,reduce
from heapq import heappush,heappop,heapify,heappushpop,_heappop_max,_heapify_max
def _heappush_max(heap,item):
    heap.append(item)
    heapq._siftdown_max(heap, 0, len(heap)-1)
def _heappushpop_max(heap, item):
    if heap and item < heap[0]:
        item, heap[0] = heap[0], item
        heapq._siftup_max(heap, 0)
    return item
from math import gcd as GCD
read=sys.stdin.read
readline=sys.stdin.readline
readlines=sys.stdin.readlines
write=sys.stdout.write
#import pypyjit
#pypyjit.set_param('max_unroll_recursion=-1')
#sys.set_int_max_str_digits(10**9)

N,M=map(int,readline().split())
A=list(map(int,readline().split()))
graph=[[] for x in range(N)]
for m in range(M):
    u,v=map(int,readline().split())
    u-=1;v-=1
    if A[u]>A[v]:
        u,v=v,u
    if A[u]<A[v]:
        graph[u].append(v)
dp=[0]*N
ans_lst=[]
K=int(readline())
for b in map(int,readline().split()):
    b-=1
    dp[b]=1
for x in sorted([x for x in range(N)],key=lambda x:A[x]):
    if dp[x]:
        dp[x]^=1
        for y in graph[x]:
            dp[y]^=1
        ans_lst.append(x)
if all(dp[x]==0 for x in range(N)):
    print(len(ans_lst))
    for m in ans_lst:
        print(m+1)
else:
    print(-1)
0