結果

問題 No.1477 Lamps on Graph
ユーザー ああいいああいい
提出日時 2021-12-27 15:17:13
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 908 ms / 2,000 ms
コード長 696 bytes
コンパイル時間 1,030 ms
コンパイル使用メモリ 11,860 KB
実行使用メモリ 37,308 KB
最終ジャッジ日時 2023-10-26 00:46:58
合計ジャッジ時間 18,827 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
10,172 KB
testcase_01 AC 29 ms
10,172 KB
testcase_02 AC 28 ms
10,172 KB
testcase_03 AC 29 ms
10,172 KB
testcase_04 AC 29 ms
10,172 KB
testcase_05 AC 29 ms
10,172 KB
testcase_06 AC 30 ms
10,172 KB
testcase_07 AC 30 ms
10,172 KB
testcase_08 AC 30 ms
10,172 KB
testcase_09 AC 31 ms
10,172 KB
testcase_10 AC 30 ms
10,172 KB
testcase_11 AC 30 ms
10,172 KB
testcase_12 AC 426 ms
21,536 KB
testcase_13 AC 433 ms
23,216 KB
testcase_14 AC 557 ms
24,436 KB
testcase_15 AC 256 ms
15,116 KB
testcase_16 AC 117 ms
15,604 KB
testcase_17 AC 125 ms
15,728 KB
testcase_18 AC 461 ms
30,312 KB
testcase_19 AC 388 ms
23,568 KB
testcase_20 AC 190 ms
14,084 KB
testcase_21 AC 383 ms
27,576 KB
testcase_22 AC 150 ms
12,284 KB
testcase_23 AC 372 ms
16,660 KB
testcase_24 AC 678 ms
29,036 KB
testcase_25 AC 247 ms
15,376 KB
testcase_26 AC 547 ms
28,704 KB
testcase_27 AC 267 ms
16,248 KB
testcase_28 AC 290 ms
19,028 KB
testcase_29 AC 345 ms
18,460 KB
testcase_30 AC 239 ms
21,124 KB
testcase_31 AC 155 ms
17,728 KB
testcase_32 AC 908 ms
37,308 KB
testcase_33 AC 819 ms
36,880 KB
testcase_34 AC 683 ms
33,484 KB
testcase_35 AC 798 ms
34,940 KB
testcase_36 AC 749 ms
33,736 KB
testcase_37 AC 573 ms
29,340 KB
testcase_38 AC 636 ms
30,704 KB
testcase_39 AC 737 ms
33,452 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M = map(int,input().split())
A = list(map(int,input().split()))
G = [[] for _ in range(N+1)]
for _ in range(M):
    u,v = map(int,input().split())
    if A[u-1] < A[v-1]:
        G[u].append(v)
    elif A[u-1] > A[v-1]:
        G[v].append(u)
K = int(input())
B = list(map(int,input().split()))
memo = [False] * (N + 1)
for b in B:
    memo[b] = True
import heapq
q = [(A[b-1],b) for b in B]
heapq.heapify(q)
ans = []
while (len(q)):
    a,b = heapq.heappop(q)
    if memo[b] == False:
        continue
    ans.append(b)
    memo[b] = False
    for v in G[b]:
        memo[v] = not memo[v]
        if memo[v]:
            heapq.heappush(q,(A[v-1],v))
print(len(ans))
for a in ans:
    print(a)
0