結果

問題 No.1477 Lamps on Graph
ユーザー tobusakanatobusakana
提出日時 2022-11-27 14:42:11
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 328 ms / 2,000 ms
コード長 1,052 bytes
コンパイル時間 1,785 ms
コンパイル使用メモリ 85,964 KB
実行使用メモリ 116,512 KB
最終ジャッジ日時 2023-07-27 10:02:56
合計ジャッジ時間 11,442 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 87 ms
71,120 KB
testcase_01 AC 85 ms
71,188 KB
testcase_02 AC 90 ms
71,172 KB
testcase_03 AC 87 ms
71,080 KB
testcase_04 AC 88 ms
71,008 KB
testcase_05 AC 86 ms
71,112 KB
testcase_06 AC 87 ms
71,164 KB
testcase_07 AC 87 ms
70,944 KB
testcase_08 AC 86 ms
71,152 KB
testcase_09 AC 88 ms
71,008 KB
testcase_10 AC 87 ms
70,968 KB
testcase_11 AC 87 ms
70,996 KB
testcase_12 AC 256 ms
85,372 KB
testcase_13 AC 206 ms
87,696 KB
testcase_14 AC 231 ms
86,740 KB
testcase_15 AC 162 ms
80,596 KB
testcase_16 AC 159 ms
82,712 KB
testcase_17 AC 157 ms
82,560 KB
testcase_18 AC 204 ms
99,492 KB
testcase_19 AC 207 ms
87,972 KB
testcase_20 AC 154 ms
79,548 KB
testcase_21 AC 203 ms
95,708 KB
testcase_22 AC 150 ms
77,836 KB
testcase_23 AC 198 ms
81,316 KB
testcase_24 AC 287 ms
95,796 KB
testcase_25 AC 173 ms
80,440 KB
testcase_26 AC 256 ms
94,740 KB
testcase_27 AC 172 ms
81,672 KB
testcase_28 AC 194 ms
85,200 KB
testcase_29 AC 191 ms
82,464 KB
testcase_30 AC 134 ms
89,700 KB
testcase_31 AC 151 ms
83,660 KB
testcase_32 AC 207 ms
116,512 KB
testcase_33 AC 202 ms
112,148 KB
testcase_34 AC 198 ms
107,036 KB
testcase_35 AC 318 ms
99,192 KB
testcase_36 AC 321 ms
97,284 KB
testcase_37 AC 307 ms
95,436 KB
testcase_38 AC 310 ms
95,104 KB
testcase_39 AC 328 ms
97,244 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
readline = sys.stdin.readline
N,M = map(int,readline().split())
A = list(map(int,readline().split()))
G = [[] for i in range(N)]
indegree = [0] * N
for _ in range(M):
    u,v = map(int,readline().split())
    u -= 1
    v -= 1
    if A[u] < A[v]:
        G[u].append(v)
        indegree[v] += 1
    if A[u] > A[v]:
        G[v].append(u)
        indegree[u] += 1
        
starts = []
for i in range(N):
    if indegree[i] == 0:
        starts.append(i)
        
K = int(readline())
B = list(map(int,readline().split()))
lamp_on = [False] * N
for b in B:
    lamp_on[b - 1] = True

ans = []    
while starts:
    next_starts = []
    for s in starts:
        if lamp_on[s]:
            lamp_on[s] = False
            ans.append(s)
            for child in G[s]:
                lamp_on[child] ^= True
        for child in G[s]:
            indegree[child] -= 1
            if indegree[child] == 0:
                next_starts.append(child)
    starts = next_starts
    
print(len(ans))
for a in ans:
    print(a + 1)
            
            
0