結果

問題 No.1477 Lamps on Graph
ユーザー FromBooskaFromBooska
提出日時 2023-09-03 20:55:53
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 1,260 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 86,940 KB
実行使用メモリ 105,568 KB
最終ジャッジ日時 2023-09-03 20:56:06
合計ジャッジ時間 12,307 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 95 ms
71,528 KB
testcase_01 AC 91 ms
71,616 KB
testcase_02 AC 92 ms
71,428 KB
testcase_03 AC 91 ms
71,704 KB
testcase_04 AC 96 ms
71,584 KB
testcase_05 AC 93 ms
71,732 KB
testcase_06 AC 92 ms
71,704 KB
testcase_07 AC 94 ms
71,676 KB
testcase_08 AC 89 ms
71,652 KB
testcase_09 AC 95 ms
71,640 KB
testcase_10 AC 91 ms
71,732 KB
testcase_11 AC 89 ms
71,424 KB
testcase_12 AC 256 ms
86,636 KB
testcase_13 AC 243 ms
90,364 KB
testcase_14 AC 280 ms
88,212 KB
testcase_15 AC 236 ms
84,732 KB
testcase_16 AC 182 ms
84,032 KB
testcase_17 AC 186 ms
83,812 KB
testcase_18 AC 233 ms
97,552 KB
testcase_19 AC 241 ms
89,580 KB
testcase_20 AC 223 ms
80,404 KB
testcase_21 AC 223 ms
93,624 KB
testcase_22 AC 172 ms
79,780 KB
testcase_23 AC 228 ms
83,632 KB
testcase_24 AC 304 ms
95,612 KB
testcase_25 AC 205 ms
83,320 KB
testcase_26 AC 287 ms
93,744 KB
testcase_27 AC 232 ms
85,652 KB
testcase_28 AC 246 ms
87,908 KB
testcase_29 AC 247 ms
84,196 KB
testcase_30 AC 173 ms
87,332 KB
testcase_31 AC 183 ms
84,872 KB
testcase_32 AC 245 ms
105,568 KB
testcase_33 AC 245 ms
103,852 KB
testcase_34 AC 232 ms
99,028 KB
testcase_35 AC 308 ms
98,320 KB
testcase_36 AC 319 ms
95,828 KB
testcase_37 AC 322 ms
95,608 KB
testcase_38 AC 317 ms
95,704 KB
testcase_39 AC 331 ms
95,784 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

# ACだがa条件で有向辺を張る、という前回の方針でやってみる
# 有向辺にすれば閉路はできない、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)
0