結果

問題 No.1477 Lamps on Graph
ユーザー lloyzlloyz
提出日時 2023-08-10 00:43:15
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 266 ms / 2,000 ms
コード長 805 bytes
コンパイル時間 721 ms
コンパイル使用メモリ 81,916 KB
実行使用メモリ 123,028 KB
最終ジャッジ日時 2024-04-27 18:42:32
合計ジャッジ時間 8,069 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
55,120 KB
testcase_01 AC 37 ms
53,776 KB
testcase_02 AC 37 ms
53,872 KB
testcase_03 AC 36 ms
54,924 KB
testcase_04 AC 35 ms
55,604 KB
testcase_05 AC 35 ms
54,636 KB
testcase_06 AC 35 ms
54,060 KB
testcase_07 AC 34 ms
53,804 KB
testcase_08 AC 37 ms
54,536 KB
testcase_09 AC 35 ms
54,836 KB
testcase_10 AC 36 ms
54,216 KB
testcase_11 AC 35 ms
54,480 KB
testcase_12 AC 181 ms
88,796 KB
testcase_13 AC 172 ms
94,264 KB
testcase_14 AC 203 ms
90,492 KB
testcase_15 AC 139 ms
80,876 KB
testcase_16 AC 114 ms
84,332 KB
testcase_17 AC 110 ms
84,076 KB
testcase_18 AC 171 ms
114,672 KB
testcase_19 AC 164 ms
91,388 KB
testcase_20 AC 116 ms
79,256 KB
testcase_21 AC 170 ms
110,892 KB
testcase_22 AC 103 ms
77,716 KB
testcase_23 AC 151 ms
81,340 KB
testcase_24 AC 217 ms
99,348 KB
testcase_25 AC 131 ms
80,556 KB
testcase_26 AC 193 ms
96,852 KB
testcase_27 AC 146 ms
82,756 KB
testcase_28 AC 157 ms
88,436 KB
testcase_29 AC 150 ms
84,316 KB
testcase_30 AC 118 ms
98,428 KB
testcase_31 AC 114 ms
85,676 KB
testcase_32 AC 196 ms
117,220 KB
testcase_33 AC 204 ms
110,216 KB
testcase_34 AC 185 ms
123,028 KB
testcase_35 AC 266 ms
103,396 KB
testcase_36 AC 265 ms
103,340 KB
testcase_37 AC 240 ms
98,088 KB
testcase_38 AC 254 ms
101,280 KB
testcase_39 AC 256 ms
103,460 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

from collections import defaultdict, deque

n, m = map(int, input().split())
A = list(map(int, input().split()))
IN = [0 for _ in range(n)]
G = defaultdict(list)
for _ in range(m):
    u, v = map(int, input().split())
    u -= 1
    v -= 1
    if A[u] > A[v]:
        G[v].append(u)
        IN[u] += 1
    elif A[u] < A[v]:
        G[u].append(v)
        IN[v] += 1
Que = deque([i for i in range(n) if IN[i] == 0])
k = int(input())
B = list(map(int, input().split()))
L = [0 for _ in range(n)]
for i in range(k):
    L[B[i] - 1] = 1
ANS = []
while Que:
    idx = Que.popleft()
    if L[idx] == 1:
        ANS.append(idx + 1)
    for nidx in G[idx]:
        IN[nidx] -= 1
        L[nidx] ^= L[idx]
        if IN[nidx] == 0:
            Que.append(nidx)
    L[idx] = 0
print(len(ANS))
print(*ANS, sep='\n')
0