結果

問題 No.1477 Lamps on Graph
ユーザー tobusakanatobusakana
提出日時 2022-11-27 14:33:26
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,236 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,532 KB
実行使用メモリ 580,200 KB
最終ジャッジ日時 2024-04-14 22:30:46
合計ジャッジ時間 14,493 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
59,780 KB
testcase_01 AC 38 ms
54,132 KB
testcase_02 AC 39 ms
52,732 KB
testcase_03 WA -
testcase_04 AC 39 ms
53,560 KB
testcase_05 AC 39 ms
53,016 KB
testcase_06 AC 38 ms
53,852 KB
testcase_07 AC 39 ms
54,132 KB
testcase_08 AC 39 ms
53,300 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 39 ms
53,320 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 405 ms
103,624 KB
testcase_33 MLE -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 番号が小さい頂点から大きい頂点に辺を貼る有向グラフを構成する
# 点灯している頂点で且つ番号が小さいものは、自分を消すしかないので、それを処理
# heapqに点灯している頂点の番号を入れていき、それを順に処理すればOK
# ループすることはないので、必ず全て消すことが出来る

import sys
readline = sys.stdin.readline
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
G = [[] for i in range(N)]
for _ in range(M):
    u,v = map(int,readline().split())
    u -= 1
    v -= 1
    if A[u] < A[v]:
        G[u].append(v)
    if A[u] > A[v]:
        G[v].append(u)
        
import heapq as hq
q = []
K = int(readline())
B = list(map(int,readline().split()))

lamp_on = [False] * N
for b in B:
    lamp_on[b - 1] = True
    hq.heappush(q, (A[b - 1], b - 1)) # 持ってる数値,頂点番号
    
ans = []
while q:
    num, v = hq.heappop(q)
    if not lamp_on[v]: # 既に消えていれば対象外
        continue
    ans.append(v + 1)
    for child in G[v]:
        lamp_on[child] ^= True
        if lamp_on[child]:
            hq.heappush(q, (A[child], child))

print(len(ans))
for a in ans:
    print(a)
0