結果
問題 | No.1477 Lamps on Graph |
ユーザー | hiragn |
提出日時 | 2022-11-29 21:00:12 |
言語 | PyPy3 (7.3.15) |
結果 |
TLE
|
実行時間 | - |
コード長 | 992 bytes |
コンパイル時間 | 190 ms |
コンパイル使用メモリ | 82,560 KB |
実行使用メモリ | 109,684 KB |
最終ジャッジ日時 | 2024-04-16 13:07:06 |
合計ジャッジ時間 | 11,528 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 46 ms
60,532 KB |
testcase_01 | AC | 47 ms
55,328 KB |
testcase_02 | AC | 45 ms
55,232 KB |
testcase_03 | AC | 47 ms
55,684 KB |
testcase_04 | AC | 46 ms
55,724 KB |
testcase_05 | AC | 49 ms
55,920 KB |
testcase_06 | AC | 49 ms
55,912 KB |
testcase_07 | AC | 47 ms
54,860 KB |
testcase_08 | AC | 47 ms
56,112 KB |
testcase_09 | AC | 47 ms
55,488 KB |
testcase_10 | AC | 50 ms
56,512 KB |
testcase_11 | AC | 48 ms
56,388 KB |
testcase_12 | AC | 1,234 ms
106,344 KB |
testcase_13 | AC | 1,696 ms
107,716 KB |
testcase_14 | AC | 1,723 ms
109,684 KB |
testcase_15 | AC | 362 ms
87,592 KB |
testcase_16 | AC | 518 ms
95,140 KB |
testcase_17 | AC | 593 ms
93,436 KB |
testcase_18 | TLE | - |
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 | -- | - |
ソースコード
from collections import defaultdict from graphlib import TopologicalSorter def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) adj = defaultdict(list) 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)] # トポロジカルソート ts = TopologicalSorter() for i in range(n): ts.add(i, *adj[i]) ans = [] for i in reversed(list(ts.static_order())): if not onoff[i]: # 消灯しているとき continue else: # 点灯しているとき ans.append(i + 1) for v in adj[i]: onoff[v] = not onoff[v] print(len(ans)) print(*ans, sep='\n') if __name__ == "__main__": main()