結果

問題 No.1477 Lamps on Graph
ユーザー FromBooskaFromBooska
提出日時 2023-09-03 20:55:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 248 ms / 2,000 ms
コード長 1,260 bytes
コンパイル時間 468 ms
コンパイル使用メモリ 82,036 KB
実行使用メモリ 110,192 KB
最終ジャッジ日時 2024-06-13 01:38:17
合計ジャッジ時間 7,932 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

# ACa
# Ai<Aj
# 0
N, M = map(int, input().split())
A = list(map(int, input().split()))
edges = [[] for i in range(N)]
inward = [0]*N
for i in range(M):
u, v = map(int, input().split())
u -= 1
v -= 1
if A[u] < A[v]:
edges[u].append(v)
inward[v] += 1
elif A[v] < A[u]:
edges[v].append(u)
inward[u] += 1
K = int(input())
B = list(map(int, input().split()))
switch = [0]*N
for b in B:
switch[b-1] = 1
from collections import deque
que = deque()
for i in range(N):
if inward[i] == 0:
que.append(i)
ans_list = []
while que:
current = que.popleft()
if switch[current] == 1:
ans_list.append(current)
for nxt in edges[current]:
switch[nxt] ^= 1
inward[nxt] -= 1
if inward[nxt] == 0:
que.append(nxt)
elif switch[current] == 0:
for nxt in edges[current]:
inward[nxt] -= 1
if inward[nxt] == 0:
que.append(nxt)
print(len(ans_list))
for a in ans_list:
print(a+1)
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0