結果

問題 No.1477 Lamps on Graph
ユーザー eijirou
提出日時 2021-04-16 21:12:22
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 307 ms / 2,000 ms
コード長 740 bytes
コンパイル時間 372 ms
コンパイル使用メモリ 82,280 KB
実行使用メモリ 108,480 KB
最終ジャッジ日時 2024-07-03 00:19:00
合計ジャッジ時間 8,560 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2
other AC * 38
権限があれば一括ダウンロードができます

ソースコード

diff #

from sys import stdin
input = stdin.readline

def main():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    edges = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, input().split())
        if a[u-1] < a[v-1]:
            edges[u-1].append(v-1)
        elif a[u-1] > a[v-1]:
            edges[v-1].append(u-1)
    
    k = int(input())
    switch = [0] * n
    for b in map(int, input().split()):
        switch[b-1] = 1
    
    ans = []
    for u in sorted(range(n), key=lambda x: a[x]):
        if switch[u]:
            #switch[u] = 0
            ans.append(u+1)
            for v in edges[u]:
                switch[v] ^= 1
    
    print(len(ans))
    print(*ans, sep='\n')

main()
0