結果

問題 No.1477 Lamps on Graph
ユーザー ayaoniayaoni
提出日時 2021-04-16 21:52:44
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 526 ms / 2,000 ms
コード長 1,029 bytes
コンパイル時間 671 ms
コンパイル使用メモリ 87,240 KB
実行使用メモリ 115,856 KB
最終ジャッジ日時 2023-09-16 00:23:12
合計ジャッジ時間 14,251 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 76 ms
71,260 KB
testcase_01 AC 75 ms
71,116 KB
testcase_02 AC 73 ms
71,148 KB
testcase_03 AC 75 ms
71,408 KB
testcase_04 AC 74 ms
71,176 KB
testcase_05 AC 77 ms
71,236 KB
testcase_06 AC 77 ms
71,540 KB
testcase_07 AC 75 ms
71,276 KB
testcase_08 AC 73 ms
71,316 KB
testcase_09 AC 75 ms
71,392 KB
testcase_10 AC 76 ms
71,380 KB
testcase_11 AC 75 ms
71,360 KB
testcase_12 AC 318 ms
88,772 KB
testcase_13 AC 312 ms
89,404 KB
testcase_14 AC 408 ms
91,568 KB
testcase_15 AC 229 ms
82,492 KB
testcase_16 AC 201 ms
83,500 KB
testcase_17 AC 209 ms
83,396 KB
testcase_18 AC 318 ms
95,972 KB
testcase_19 AC 325 ms
90,128 KB
testcase_20 AC 211 ms
82,108 KB
testcase_21 AC 292 ms
93,592 KB
testcase_22 AC 180 ms
79,888 KB
testcase_23 AC 270 ms
84,364 KB
testcase_24 AC 468 ms
96,712 KB
testcase_25 AC 232 ms
83,076 KB
testcase_26 AC 399 ms
96,524 KB
testcase_27 AC 219 ms
83,476 KB
testcase_28 AC 248 ms
86,436 KB
testcase_29 AC 289 ms
85,376 KB
testcase_30 AC 209 ms
87,432 KB
testcase_31 AC 202 ms
84,180 KB
testcase_32 AC 462 ms
112,380 KB
testcase_33 AC 436 ms
110,180 KB
testcase_34 AC 285 ms
115,856 KB
testcase_35 AC 510 ms
102,000 KB
testcase_36 AC 526 ms
101,548 KB
testcase_37 AC 361 ms
96,928 KB
testcase_38 AC 426 ms
97,504 KB
testcase_39 AC 449 ms
100,440 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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')
0