結果

問題 No.1477 Lamps on Graph
ユーザー ygd.ygd.
提出日時 2021-04-16 20:33:07
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 547 ms / 2,000 ms
コード長 878 bytes
コンパイル時間 481 ms
コンパイル使用メモリ 87,076 KB
実行使用メモリ 111,144 KB
最終ジャッジ日時 2023-09-15 21:26:53
合計ジャッジ時間 14,353 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 78 ms
71,412 KB
testcase_01 AC 78 ms
71,116 KB
testcase_02 AC 77 ms
71,328 KB
testcase_03 AC 77 ms
71,232 KB
testcase_04 AC 79 ms
71,424 KB
testcase_05 AC 80 ms
71,332 KB
testcase_06 AC 77 ms
71,332 KB
testcase_07 AC 77 ms
70,928 KB
testcase_08 AC 77 ms
71,352 KB
testcase_09 AC 77 ms
71,372 KB
testcase_10 AC 78 ms
71,352 KB
testcase_11 AC 80 ms
71,044 KB
testcase_12 AC 355 ms
88,508 KB
testcase_13 AC 350 ms
89,940 KB
testcase_14 AC 437 ms
90,508 KB
testcase_15 AC 258 ms
83,556 KB
testcase_16 AC 204 ms
83,232 KB
testcase_17 AC 227 ms
83,412 KB
testcase_18 AC 345 ms
97,512 KB
testcase_19 AC 356 ms
89,216 KB
testcase_20 AC 247 ms
82,840 KB
testcase_21 AC 332 ms
95,092 KB
testcase_22 AC 212 ms
79,804 KB
testcase_23 AC 268 ms
84,696 KB
testcase_24 AC 483 ms
95,544 KB
testcase_25 AC 255 ms
83,040 KB
testcase_26 AC 477 ms
95,132 KB
testcase_27 AC 265 ms
83,836 KB
testcase_28 AC 287 ms
85,672 KB
testcase_29 AC 357 ms
86,920 KB
testcase_30 AC 232 ms
86,792 KB
testcase_31 AC 229 ms
84,564 KB
testcase_32 AC 488 ms
108,028 KB
testcase_33 AC 467 ms
107,640 KB
testcase_34 AC 320 ms
111,144 KB
testcase_35 AC 547 ms
101,928 KB
testcase_36 AC 536 ms
101,404 KB
testcase_37 AC 396 ms
94,792 KB
testcase_38 AC 455 ms
97,176 KB
testcase_39 AC 543 ms
100,744 KB
権限があれば一括ダウンロードができます

ソースコード

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