結果

問題 No.1477 Lamps on Graph
ユーザー convexineq
提出日時 2021-04-16 20:14:35
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 372 ms / 2,000 ms
コード長 564 bytes
コンパイル時間 197 ms
コンパイル使用メモリ 82,264 KB
実行使用メモリ 102,916 KB
最終ジャッジ日時 2024-07-02 22:10:17
合計ジャッジ時間 9,865 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

n,m = map(int,input().split())
*a, = map(int,input().split())
g = [[] for _ in range(n)]
for _ in range(m):
    u,v = map(int,input().split())
    u -= 1
    v -= 1
    if a[u] < a[v]:
        g[u].append(v)
    if a[v] < a[u]:
        g[v].append(u)
res = [0]*n
_ = input()
for i in map(int,input().split()):
    res[i-1] = 1
ans = []
for v in sorted(range(n), key=lambda i:a[i]):
    if res[v]:
        res[v] = 0
        ans.append(v+1)
        for c in g[v]:
            res[c] ^= 1
if sum(res):
    print(-1)
else:
    print(len(ans))
    print(*ans,sep="\n")
0