結果

問題 No.1477 Lamps on Graph
ユーザー FromBooskaFromBooska
提出日時 2023-03-09 19:56:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,043 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 82,520 KB
実行使用メモリ 735,060 KB
最終ジャッジ日時 2024-09-18 03:02:07
合計ジャッジ時間 9,187 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 5 WA * 15 MLE * 1 -- * 17
権限があれば一括ダウンロードができます

ソースコード

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
# 1<3, 2<3, 3<4, 3<5
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, 0)) #2nd for switch count
while que:
current, switch = que.popleft()
#print('current', current, 'switch', switch, 'onoff', onoff)
if (onoff[current] + switch)%2 == 0:
for nxt in edges[current]:
#onoff[nxt] += switch
que.append((nxt, switch))
else:
switch_list.append(current)
for nxt in edges[current]:
#onoff[nxt] += switch+1
que.append((nxt, switch+1))
#
# N6 M5, A123456
# 21, 42, 32, 54, 53
# 3, 256
# 52
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(switch_list))
#print(*switch_list)
for a in ans_list:
print(a)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0