結果

問題 No.1477 Lamps on Graph
ユーザー FromBooskaFromBooska
提出日時 2023-03-09 21:41:53
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,792 bytes
コンパイル時間 1,025 ms
コンパイル使用メモリ 81,580 KB
実行使用メモリ 622,968 KB
最終ジャッジ日時 2023-10-18 06:27:26
合計ジャッジ時間 11,383 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
55,496 KB
testcase_01 AC 42 ms
55,496 KB
testcase_02 AC 44 ms
55,496 KB
testcase_03 AC 43 ms
55,496 KB
testcase_04 AC 43 ms
55,496 KB
testcase_05 AC 45 ms
55,496 KB
testcase_06 AC 43 ms
55,496 KB
testcase_07 AC 44 ms
55,496 KB
testcase_08 AC 42 ms
55,496 KB
testcase_09 AC 43 ms
55,496 KB
testcase_10 AC 42 ms
55,496 KB
testcase_11 AC 43 ms
55,496 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 MLE -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

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

switch_list = []

for start in range(1, N+1):
    if inward[start] > 0:
        continue
    
    que = deque()
    que.append(start)
    while que:
        current = que.popleft()
        #print('current', current, 'onoff', onoff)
        add = 0
        if onoff[current]%2 != 0:
            add = 1
            switch_list.append(current)
            onoff[current] += add
        
        for nxt in edges[current]:
            onoff[nxt] += add
            que.append(nxt) 


# 同じスイッチを2度押すのをなくす

count = [0]*(N+1)
for s in switch_list:
    count[s] += 1

ans_list = []
for s in switch_list:
    if count[s] == 1:
        count[s] -= 1
        ans_list.append(s)
    elif count[s] > 1:
        count[s] -= 1

print(len(ans_list))
for a in ans_list:
    print(a)

0