結果

問題 No.1477 Lamps on Graph
ユーザー hiragnhiragn
提出日時 2022-11-29 22:49:52
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 660 bytes
コンパイル時間 264 ms
コンパイル使用メモリ 82,176 KB
実行使用メモリ 106,900 KB
最終ジャッジ日時 2024-04-16 13:34:23
合計ジャッジ時間 12,457 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 42 ms
52,224 KB
testcase_01 AC 42 ms
52,480 KB
testcase_02 AC 42 ms
52,352 KB
testcase_03 AC 43 ms
52,480 KB
testcase_04 AC 42 ms
52,352 KB
testcase_05 AC 43 ms
52,352 KB
testcase_06 AC 43 ms
52,736 KB
testcase_07 AC 43 ms
52,352 KB
testcase_08 AC 43 ms
52,608 KB
testcase_09 AC 43 ms
52,864 KB
testcase_10 AC 45 ms
52,352 KB
testcase_11 AC 44 ms
52,352 KB
testcase_12 AC 356 ms
85,408 KB
testcase_13 AC 369 ms
89,752 KB
testcase_14 AC 395 ms
87,716 KB
testcase_15 AC 256 ms
80,672 KB
testcase_16 AC 196 ms
82,304 KB
testcase_17 AC 225 ms
81,920 KB
testcase_18 AC 331 ms
93,560 KB
testcase_19 AC 285 ms
86,912 KB
testcase_20 AC 230 ms
80,568 KB
testcase_21 AC 304 ms
93,488 KB
testcase_22 AC 182 ms
78,336 KB
testcase_23 AC 256 ms
81,036 KB
testcase_24 AC 483 ms
95,008 KB
testcase_25 AC 232 ms
80,312 KB
testcase_26 AC 356 ms
92,676 KB
testcase_27 AC 266 ms
82,184 KB
testcase_28 AC 279 ms
84,384 KB
testcase_29 AC 275 ms
82,692 KB
testcase_30 AC 225 ms
86,708 KB
testcase_31 AC 214 ms
82,560 KB
testcase_32 AC 490 ms
106,900 KB
testcase_33 AC 465 ms
105,108 KB
testcase_34 AC 299 ms
100,464 KB
testcase_35 AC 499 ms
98,076 KB
testcase_36 AC 532 ms
96,036 KB
testcase_37 AC 398 ms
94,464 KB
testcase_38 AC 458 ms
93,952 KB
testcase_39 AC 464 ms
95,512 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