結果

問題 No.1477 Lamps on Graph
ユーザー ygd.ygd.
提出日時 2021-04-16 20:31:15
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 749 bytes
コンパイル時間 381 ms
コンパイル使用メモリ 87,264 KB
実行使用メモリ 111,416 KB
最終ジャッジ日時 2023-09-15 21:21:58
合計ジャッジ時間 15,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,380 KB
testcase_01 AC 77 ms
71,512 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 76 ms
71,440 KB
testcase_05 WA -
testcase_06 AC 77 ms
71,496 KB
testcase_07 AC 75 ms
71,360 KB
testcase_08 AC 77 ms
71,408 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 76 ms
71,228 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 411 ms
107,992 KB
testcase_33 WA -
testcase_34 AC 330 ms
111,416 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

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]:
            Status[adj] = 0
    
print(len(ret))
print(*ret,sep="\n")
0