結果

問題 No.1477 Lamps on Graph
ユーザー 👑 timitimi
提出日時 2023-01-05 09:04:49
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 355 ms / 2,000 ms
コード長 844 bytes
コンパイル時間 284 ms
コンパイル使用メモリ 87,248 KB
実行使用メモリ 118,768 KB
最終ジャッジ日時 2023-08-19 07:34:52
合計ジャッジ時間 14,407 ms
ジャッジサーバーID
(参考情報)
judge10 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 92 ms
71,808 KB
testcase_01 AC 90 ms
71,684 KB
testcase_02 AC 92 ms
71,428 KB
testcase_03 AC 89 ms
71,896 KB
testcase_04 AC 89 ms
71,760 KB
testcase_05 AC 90 ms
71,948 KB
testcase_06 AC 89 ms
71,584 KB
testcase_07 AC 90 ms
71,596 KB
testcase_08 AC 91 ms
71,740 KB
testcase_09 AC 90 ms
71,936 KB
testcase_10 AC 92 ms
71,592 KB
testcase_11 AC 90 ms
71,564 KB
testcase_12 AC 255 ms
89,316 KB
testcase_13 AC 254 ms
96,980 KB
testcase_14 AC 285 ms
92,176 KB
testcase_15 AC 217 ms
85,308 KB
testcase_16 AC 191 ms
84,596 KB
testcase_17 AC 189 ms
84,408 KB
testcase_18 AC 245 ms
106,732 KB
testcase_19 AC 241 ms
91,324 KB
testcase_20 AC 184 ms
80,492 KB
testcase_21 AC 223 ms
99,152 KB
testcase_22 AC 178 ms
82,372 KB
testcase_23 AC 241 ms
84,556 KB
testcase_24 AC 319 ms
102,328 KB
testcase_25 AC 209 ms
82,716 KB
testcase_26 AC 286 ms
98,964 KB
testcase_27 AC 228 ms
86,868 KB
testcase_28 AC 245 ms
90,336 KB
testcase_29 AC 231 ms
87,384 KB
testcase_30 AC 182 ms
92,420 KB
testcase_31 AC 194 ms
86,288 KB
testcase_32 AC 278 ms
118,768 KB
testcase_33 AC 273 ms
110,016 KB
testcase_34 AC 237 ms
106,952 KB
testcase_35 AC 355 ms
105,944 KB
testcase_36 AC 354 ms
102,176 KB
testcase_37 AC 332 ms
95,936 KB
testcase_38 AC 335 ms
98,060 KB
testcase_39 AC 347 ms
102,396 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int, input().split())
A=list(map(int, input().split()))
G=[[]for i in range(N)]
deg=[0]*N
for i in range(M):
  a,b=map(int, input().split())
  a-=1
  b-=1
  if A[a]<A[b]:
    G[a].append(b)
    deg[b]+=1
  if A[a]>A[b]:
    G[b].append(a)
    deg[a]+=1
V=N
# V:頂点数
# G[v] = [w, ...]:有向グラフ上の頂点vから到達できる頂点w
# deg[v]:頂点vに到達できる頂点の数
from collections import deque
ans = list(v for v in range(V) if deg[v] == 0)
deq = deque(ans)
used = [0] * V
while deq:
  v=deq.popleft()
  for t in G[v]:
    deg[t]-=1
    if deg[t]==0:
      deq.append(t)
      ans.append(t)

L=[0]*N
K=int(input())
B=list(map(int, input().split()))
for b in B:
  L[b-1]=1
F=[]
for i in ans:
  if L[i]==1:
    F.append(i+1)
    for nex in G[i]:
      L[nex]=1-L[nex]
print(len(F))
for f in F:
  print(f)
    
0