結果

問題 No.1477 Lamps on Graph
ユーザー hiragnhiragn
提出日時 2022-11-29 21:35:29
言語 Python3
(3.12.2 + numpy 1.26.4 + scipy 1.12.0)
結果
TLE  
実行時間 -
コード長 891 bytes
コンパイル時間 183 ms
コンパイル使用メモリ 12,800 KB
実行使用メモリ 28,296 KB
最終ジャッジ日時 2024-04-16 13:18:37
合計ジャッジ時間 4,898 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
16,512 KB
testcase_01 AC 30 ms
10,880 KB
testcase_02 AC 32 ms
11,008 KB
testcase_03 AC 30 ms
11,008 KB
testcase_04 AC 31 ms
10,880 KB
testcase_05 AC 30 ms
10,880 KB
testcase_06 AC 30 ms
10,880 KB
testcase_07 AC 30 ms
10,880 KB
testcase_08 AC 30 ms
11,008 KB
testcase_09 AC 31 ms
10,880 KB
testcase_10 AC 31 ms
11,008 KB
testcase_11 AC 30 ms
11,008 KB
testcase_12 TLE -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
testcase_30 -- -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
testcase_36 -- -
testcase_37 -- -
testcase_38 -- -
testcase_39 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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

    adj = [[] for _ in range(n)]
    for _ in range(m):
        u, v = map(int, input().split())
        u -= 1
        v -= 1
        if a[u] < a[v]:
            adj[u].append(v)
        if a[v] < a[u]:
            adj[v].append(u)

    _ = int(input())
    b = list(map(lambda x: int(x) - 1, input().split()))
    onoff = [(i in b) for i in range(n)]

    import heapq
    hq = [(a[i], i) for i in b]
    heapq.heapify(hq)

    ans = []
    while hq:
        x, y = heapq.heappop(hq)
        if not onoff[y]:
            continue
        ans.append(y + 1)
        onoff[y] = False
        for v in adj[y]:
            onoff[v] = not onoff[v]
            if onoff[v]:
                heapq.heappush(hq, (a[v], v))

    print(len(ans))
    print(*ans, sep='\n')


if __name__ == "__main__":
    main()
0