結果

問題 No.1477 Lamps on Graph
コンテスト
ユーザー 小野寺健
提出日時 2021-04-27 08:08:44
言語 Python3
(3.14.3 + numpy 2.4.2 + scipy 1.17.0)
コンパイル:
python3 -mpy_compile _filename_
実行:
python3 _filename_
結果
AC  
実行時間 674 ms / 2,000 ms
コード長 870 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 538 ms
コンパイル使用メモリ 20,832 KB
実行使用メモリ 55,240 KB
最終ジャッジ日時 2026-03-27 10:31:40
合計ジャッジ時間 16,604 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

class Peek:
    def __init__(self, i, A):
        self.i = i
        self.A = A
        self.V = []
        self.B = False
    def __str__(self):
        return str(self.i) + ":" + str(self.A) + "," + str(self.B) + "," + str(self.V)
        
N, M = map(int, input().split())

A = []
for i, a in enumerate(list(map(int, input().split()))):
    A.append(Peek(i, a))
    
for _ in range(M):
    u, v = map(int, input().split())
    A[u-1].V.append(v-1)
    A[v-1].V.append(u-1)
    
K = int(input())
for b in list(map(int, input().split())):
    A[b-1].B = True

S = sorted(A, key=lambda x: x.A)

op = []
for p in S:
    if p.B :
        p.B = False
        op.append(p.i+1)
        for i in p.V:
            if p.A < A[i].A:
                A[i].B = not A[i].B
            
if any([i.B for i in A]):
    print(-1)
else:
    print(len(op))
    for p in op:
        print(p)
0