結果
問題 |
No.1477 Lamps on Graph
|
ユーザー |
![]() |
提出日時 | 2021-05-12 20:11:26 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 718 bytes |
コンパイル時間 | 367 ms |
コンパイル使用メモリ | 82,404 KB |
実行使用メモリ | 93,120 KB |
最終ジャッジ日時 | 2024-09-23 06:49:48 |
合計ジャッジ時間 | 10,287 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 16 TLE * 1 -- * 21 |
ソースコード
import collections N, M = map(int, input().split()) A = list(map(lambda x: int(x) - 1, input().split())) G = collections.defaultdict(list) for _ in range(M): v0, v1 = map(lambda x: int(x) - 1, input().split()) G[v0].append(v1) G[v1].append(v0) K = int(input()) B = list(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')