結果
| 問題 | 
                            No.1477 Lamps on Graph
                             | 
                    
| コンテスト | |
| ユーザー | 
                             ayaoni
                         | 
                    
| 提出日時 | 2021-04-16 21:52:44 | 
| 言語 | PyPy3  (7.3.15)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 494 ms / 2,000 ms | 
| コード長 | 1,029 bytes | 
| コンパイル時間 | 216 ms | 
| コンパイル使用メモリ | 82,048 KB | 
| 実行使用メモリ | 114,560 KB | 
| 最終ジャッジ日時 | 2024-07-03 01:32:03 | 
| 合計ジャッジ時間 | 12,630 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge1 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 2 | 
| other | AC * 38 | 
ソースコード
import sys
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def LS2(): return list(sys.stdin.readline().rstrip())
N,M = MI()
A = [0]+LI()
Graph = [[] for _ in range(N+1)]
for _ in range(M):
    u,v = MI()
    Graph[u].append(v)
    Graph[v].append(u)
K = I()
B = LI()
C = []
is_light = [0]*(N+1)
for b in B:
    heappush(C,(A[b],b))
    is_light[b] = 1
ANS = []
while C:
    a,u = heappop(C)
    if not is_light[u]:
        continue
    ANS.append(u)
    is_light[u] = 0
    for v in Graph[u]:
        if a < A[v]:
            is_light[v] ^= 1
            if is_light[v]:
                heappush(C,(A[v],v))
print(len(ANS))
print(*ANS,sep='\n')
            
            
            
        
            
ayaoni