結果

問題 No.1477 Lamps on Graph
ユーザー DrDrpilotDrDrpilot
提出日時 2022-03-15 12:34:28
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
AC  
実行時間 819 ms / 2,000 ms
コード長 655 bytes
コンパイル時間 375 ms
コンパイル使用メモリ 11,872 KB
実行使用メモリ 40,204 KB
最終ジャッジ日時 2023-10-22 02:58:52
合計ジャッジ時間 16,487 ms
ジャッジサーバーID
(参考情報)
judge9 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
10,292 KB
testcase_01 AC 25 ms
10,292 KB
testcase_02 AC 25 ms
10,292 KB
testcase_03 AC 26 ms
10,292 KB
testcase_04 AC 26 ms
10,292 KB
testcase_05 AC 30 ms
10,292 KB
testcase_06 AC 29 ms
10,292 KB
testcase_07 AC 26 ms
10,292 KB
testcase_08 AC 26 ms
10,292 KB
testcase_09 AC 27 ms
10,292 KB
testcase_10 AC 28 ms
10,292 KB
testcase_11 AC 27 ms
10,292 KB
testcase_12 AC 418 ms
22,164 KB
testcase_13 AC 430 ms
24,860 KB
testcase_14 AC 523 ms
24,884 KB
testcase_15 AC 233 ms
15,172 KB
testcase_16 AC 107 ms
15,880 KB
testcase_17 AC 112 ms
16,056 KB
testcase_18 AC 386 ms
32,924 KB
testcase_19 AC 318 ms
23,648 KB
testcase_20 AC 171 ms
14,636 KB
testcase_21 AC 339 ms
29,780 KB
testcase_22 AC 141 ms
12,336 KB
testcase_23 AC 325 ms
16,772 KB
testcase_24 AC 618 ms
30,976 KB
testcase_25 AC 228 ms
15,688 KB
testcase_26 AC 499 ms
30,348 KB
testcase_27 AC 249 ms
16,312 KB
testcase_28 AC 267 ms
19,464 KB
testcase_29 AC 303 ms
19,372 KB
testcase_30 AC 196 ms
22,600 KB
testcase_31 AC 131 ms
18,048 KB
testcase_32 AC 819 ms
39,956 KB
testcase_33 AC 748 ms
40,204 KB
testcase_34 AC 629 ms
37,072 KB
testcase_35 AC 723 ms
37,216 KB
testcase_36 AC 702 ms
35,428 KB
testcase_37 AC 522 ms
29,584 KB
testcase_38 AC 588 ms
31,432 KB
testcase_39 AC 707 ms
35,104 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import heapq
n,m=map(int,input().split())
a=list(map(int,input().split()))
g=[[] for _ in range(n)]
for _ in range(m):
    u,v=map(int,input().split())
    u-=1;v-=1
    if a[u]<a[v]:
        g[u].append(v)
    if a[u]>a[v]:
        g[v].append(u)
k=int(input())
b=list(map(int,input().split()))
memo=[0]*n
for i in b:
    memo[i-1]=1
q=[(a[i-1],i-1) for i in b]
heapq.heapify(q)
ans=[]
while q:
    num,now=heapq.heappop(q)
    if memo[now]==0:
        continue
    ans.append(now)
    memo[now]=0
    for to in g[now]:
        memo[to]=1-memo[to]
        if memo[to]:
            heapq.heappush(q,(a[to],to))
print(len(ans))
for i in ans:
    print(i+1)
0