結果

問題 No.1477 Lamps on Graph
ユーザー O2MTO2MT
提出日時 2021-04-17 03:27:51
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 315 ms / 2,000 ms
コード長 901 bytes
コンパイル時間 275 ms
コンパイル使用メモリ 86,968 KB
実行使用メモリ 117,872 KB
最終ジャッジ日時 2023-09-16 07:49:58
合計ジャッジ時間 11,006 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 71 ms
71,136 KB
testcase_01 AC 71 ms
71,260 KB
testcase_02 AC 71 ms
71,176 KB
testcase_03 AC 71 ms
71,516 KB
testcase_04 AC 72 ms
71,228 KB
testcase_05 AC 73 ms
71,136 KB
testcase_06 AC 73 ms
71,344 KB
testcase_07 AC 74 ms
71,012 KB
testcase_08 AC 70 ms
71,248 KB
testcase_09 AC 71 ms
71,284 KB
testcase_10 AC 72 ms
71,404 KB
testcase_11 AC 73 ms
71,028 KB
testcase_12 AC 237 ms
86,080 KB
testcase_13 AC 225 ms
91,716 KB
testcase_14 AC 266 ms
88,028 KB
testcase_15 AC 190 ms
81,352 KB
testcase_16 AC 169 ms
83,384 KB
testcase_17 AC 162 ms
83,436 KB
testcase_18 AC 208 ms
104,924 KB
testcase_19 AC 207 ms
89,100 KB
testcase_20 AC 158 ms
79,784 KB
testcase_21 AC 188 ms
92,904 KB
testcase_22 AC 148 ms
78,904 KB
testcase_23 AC 205 ms
82,824 KB
testcase_24 AC 271 ms
96,900 KB
testcase_25 AC 181 ms
80,140 KB
testcase_26 AC 241 ms
95,000 KB
testcase_27 AC 193 ms
82,632 KB
testcase_28 AC 213 ms
85,988 KB
testcase_29 AC 201 ms
83,936 KB
testcase_30 AC 151 ms
92,016 KB
testcase_31 AC 168 ms
84,844 KB
testcase_32 AC 233 ms
117,872 KB
testcase_33 AC 234 ms
112,016 KB
testcase_34 AC 205 ms
111,588 KB
testcase_35 AC 315 ms
99,616 KB
testcase_36 AC 311 ms
97,608 KB
testcase_37 AC 299 ms
96,836 KB
testcase_38 AC 306 ms
96,916 KB
testcase_39 AC 308 ms
97,584 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin, setrecursionlimit
setrecursionlimit(10**7)
N,M = map(int,input().split())
A = list(map(int,input().split()))
l = [[] for _ in range(N)]
for _ in range(M):
    a,b = map(int,input().split())
    a -= 1
    b -= 1
    if A[a] < A[b]:
        l[a].append(b)
    if A[b] < A[a]:
        l[b].append(a)
K = int(input())
B = list(map(int,input().split()))
lamps = [0]*N
for b in B:
    lamps[b-1] = 1
dag = [0]*N
for i in range(N):
    for j in l[i]:
        dag[j] += 1
que, dir = [], []
for i in range(N):
    if dag[i] == 0:
        que.append(i)
while que:
    cursor = que.pop()
    if lamps[cursor] == 1:
        dir.append(cursor)
        for nextCursor in l[cursor]:
            lamps[nextCursor] ^= 1
    for nextCursor in l[cursor]:
        dag[nextCursor] -= 1
        if dag[nextCursor] == 0:
            que.append(nextCursor)
print(len(dir))
for d in dir:
    print(d+1)
0