結果
| 問題 | No.1477 Lamps on Graph |
| コンテスト | |
| ユーザー |
lie_of_lillie
|
| 提出日時 | 2021-05-12 20:23:22 |
| 言語 | Python3 (3.14.3 + numpy 2.4.4 + scipy 1.17.1) |
| 結果 |
AC
|
| 実行時間 | 630 ms / 2,000 ms |
| コード長 | 771 bytes |
| 記録 | |
| コンパイル時間 | 361 ms |
| コンパイル使用メモリ | 20,568 KB |
| 実行使用メモリ | 73,160 KB |
| 最終ジャッジ日時 | 2026-04-11 12:25:54 |
| 合計ジャッジ時間 | 15,281 ms |
|
ジャッジサーバーID (参考情報) |
judge1_0 / judge2_1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 38 |
ソースコード
import collections
N, M = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
G = collections.defaultdict(set)
for _ in range(M):
v0, v1 = map(lambda x: int(x) - 1, input().split())
# 計算量の削減
if A[v0] < A[v1]:
G[v0].add(v1)
else:
G[v1].add(v0)
K = int(input())
B = set(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')
lie_of_lillie