結果

問題 No.1477 Lamps on Graph
ユーザー FromBooskaFromBooska
提出日時 2023-03-09 22:05:13
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,647 bytes
コンパイル時間 1,556 ms
コンパイル使用メモリ 81,576 KB
実行使用メモリ 115,628 KB
最終ジャッジ日時 2023-10-18 06:29:21
合計ジャッジ時間 12,058 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
55,516 KB
testcase_01 AC 40 ms
55,516 KB
testcase_02 AC 40 ms
55,516 KB
testcase_03 AC 40 ms
55,516 KB
testcase_04 AC 40 ms
55,516 KB
testcase_05 AC 40 ms
55,516 KB
testcase_06 AC 41 ms
55,516 KB
testcase_07 AC 40 ms
55,516 KB
testcase_08 AC 42 ms
55,516 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 41 ms
55,516 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 AC 124 ms
89,768 KB
testcase_31 WA -
testcase_32 AC 215 ms
115,628 KB
testcase_33 AC 223 ms
111,436 KB
testcase_34 AC 187 ms
109,608 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 整数の大小関係で有効グラフになる
# 各連結成分ごとに調べる、そのために入次数0を記録
# 連結成分でON=[0101]を調べる、連結成分の始めから見ていく
# switch使ったら記録
# BFS or DFSだろう
# 問題読み違えていた、ランプは次だけ変わる

N, M = map(int, input().split())
A = [0]+list(map(int, input().split()))
edges = [[] for i in range(N+1)]
inward = [0]*(N+1)
for i in range(M):
    u, v = map(int, input().split())
    if A[u] < A[v]:
        edges[u].append(v)
        inward[v] = 1
    elif A[u] > A[v]:
        edges[v].append(u)
        inward[u] = 1

K = int(input())
B = list(map(int, input().split()))


# その連結成分の始めからやらないと最小手順にならない
# ということは連結成分の最初を探す必要がある, degree check
# 問題読み違えていた、ランプは次だけ変わる

from collections import deque

onoff = [0]*(N+1)
for b in B:
    onoff[b] = 1
    
start = []
for i in range(1, N+1):
    if inward[i] == 0:
        start.append(i)

switch_list = []

ans = []    
while start:
    next_start = []
    for s in start:
        if onoff[s] == 1:
            # スイッチ押す
            onoff[s] = 0
            ans.append(s)
            for nxt in edges[s]:
                onoff[nxt] ^= 1
        for nxt in edges[s]:
            inward[nxt] -= 1
            # 入次数がゼロになれば、その頂点以前はすべて処理済みということ
            if inward[nxt] == 0:
                next_start.append(nxt)
    start = next_start
    
print(len(ans))
for a in ans:
    print(a)
0