結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-04-16 20:33:07 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 435 ms / 2,000 ms |
コード長 | 878 bytes |
コンパイル時間 | 165 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 115,884 KB |
最終ジャッジ日時 | 2024-07-02 22:55:45 |
合計ジャッジ時間 | 10,728 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
from heapq import heapify, heappop, heappush N,M = map(int,input().split()) A = list(map(int,input().split())) G = [[] for _ in range(N)] for i in range(M): u,v = map(int,input().split()) u-=1;v-=1 G[u].append(v) G[v].append(u) K = int(input()) B = list(map(int,input().split())) B = [b-1 for b in B] Status = [0]*N HQ = [] for b in B: Status[b] = 1 for i in range(N): if Status[i] == 1: heappush(HQ,(A[i],i)) #value, index ret = [] while HQ: val,idx = heappop(HQ) if Status[idx] == 0: #消灯していたらスキップ continue Status[idx] = 0 ret.append(idx+1) #1index for adj in G[idx]: if A[adj] > A[idx]: if Status[adj] == 0: Status[adj] = 1 heappush(HQ,(A[adj],adj)) else: Status[adj] = 0 print(len(ret)) print(*ret,sep="\n")