結果

問題 No.1477 Lamps on Graph
ユーザー NoaSaberNoaSaber
提出日時 2021-04-16 22:18:45
言語 PyPy3
(7.3.13)
結果
WA  
実行時間 -
コード長 707 bytes
コンパイル時間 261 ms
コンパイル使用メモリ 87,036 KB
実行使用メモリ 113,088 KB
最終ジャッジ日時 2023-09-16 01:08:13
合計ジャッジ時間 15,336 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 73 ms
71,244 KB
testcase_01 AC 73 ms
71,372 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 76 ms
71,544 KB
testcase_05 WA -
testcase_06 AC 75 ms
71,644 KB
testcase_07 AC 75 ms
71,312 KB
testcase_08 AC 76 ms
71,520 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 AC 77 ms
71,408 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 AC 435 ms
113,088 KB
testcase_33 WA -
testcase_34 AC 317 ms
106,652 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

N,M=map(int,input().split())
A=list(map(int,input().split()))
edge=[[] for i in range(N)]
score=[0]*N
for i in range(M):
    u,v=map(int,input().split())
    u-=1;v-=1
    if A[u]<A[v]:
        edge[u].append(v)
    if A[v]<A[u]:
        edge[v].append(u)
K=int(input())
B=list(map(int,input().split()))
q=[]
ans=0
for i in B:
    score[i-1]=1
    q.append((A[i-1],i-1))
import heapq
heapq.heapify(q)
ans_l=[]
while q:
    value,next=heapq.heappop(q)
    if score[next]%2==0:
        continue
    ans+=1
    ans_l.append(next)
    for i in edge[next]:
        score[i]=score[next]+1
        if score[i]%2==1:
            heapq.heappush(q,(A[i],i))
    score[next]=0
print(ans)
for i in ans_l:
    print(i+1)
0