結果
問題 | No.1477 Lamps on Graph |
ユーザー | Shirotsume |
提出日時 | 2023-02-17 21:17:34 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 559 ms / 2,000 ms |
コード長 | 1,416 bytes |
コンパイル時間 | 474 ms |
コンパイル使用メモリ | 87,040 KB |
実行使用メモリ | 116,852 KB |
最終ジャッジ日時 | 2023-09-26 18:21:46 |
合計ジャッジ時間 | 17,139 ms |
ジャッジサーバーID (参考情報) |
judge12 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 95 ms
71,436 KB |
testcase_01 | AC | 93 ms
71,748 KB |
testcase_02 | AC | 94 ms
71,528 KB |
testcase_03 | AC | 93 ms
71,676 KB |
testcase_04 | AC | 96 ms
71,592 KB |
testcase_05 | AC | 93 ms
71,600 KB |
testcase_06 | AC | 95 ms
71,580 KB |
testcase_07 | AC | 98 ms
71,332 KB |
testcase_08 | AC | 96 ms
71,860 KB |
testcase_09 | AC | 96 ms
71,616 KB |
testcase_10 | AC | 98 ms
71,548 KB |
testcase_11 | AC | 94 ms
71,692 KB |
testcase_12 | AC | 361 ms
89,648 KB |
testcase_13 | AC | 340 ms
90,616 KB |
testcase_14 | AC | 436 ms
91,392 KB |
testcase_15 | AC | 256 ms
83,856 KB |
testcase_16 | AC | 236 ms
85,540 KB |
testcase_17 | AC | 238 ms
84,972 KB |
testcase_18 | AC | 352 ms
97,004 KB |
testcase_19 | AC | 366 ms
91,188 KB |
testcase_20 | AC | 249 ms
82,880 KB |
testcase_21 | AC | 341 ms
94,576 KB |
testcase_22 | AC | 221 ms
80,864 KB |
testcase_23 | AC | 290 ms
85,872 KB |
testcase_24 | AC | 504 ms
96,668 KB |
testcase_25 | AC | 270 ms
84,284 KB |
testcase_26 | AC | 432 ms
95,428 KB |
testcase_27 | AC | 245 ms
84,028 KB |
testcase_28 | AC | 288 ms
87,380 KB |
testcase_29 | AC | 328 ms
86,056 KB |
testcase_30 | AC | 241 ms
91,904 KB |
testcase_31 | AC | 234 ms
86,716 KB |
testcase_32 | AC | 498 ms
108,964 KB |
testcase_33 | AC | 476 ms
108,780 KB |
testcase_34 | AC | 307 ms
116,852 KB |
testcase_35 | AC | 551 ms
102,252 KB |
testcase_36 | AC | 559 ms
101,596 KB |
testcase_37 | AC | 385 ms
97,320 KB |
testcase_38 | AC | 474 ms
97,652 KB |
testcase_39 | AC | 481 ms
100,048 KB |
ソースコード
import sys from collections import deque, Counter input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 import heapq class Heap(): def __init__(self, maxi = False): self.sum = 0 self.al = [] self.maxi = maxi self.len = 0 def __len__(self): return len(self.al) def add(self, x): if self.maxi: heapq.heappush(self.al, -x) else: heapq.heappush(self.al, x) def pop(self): if self.maxi: now = heapq.heappop(self.al) return -now else: now = heapq.heappop(self.al) return now def top(self): now = self.pop() self.add(now) return now n, m = mi() a = li() graph = [[] for _ in range(n)] for _ in range(m): u, v = mi() u -= 1; v -= 1 graph[u].append(v) graph[v].append(u) k = li() b = li() H = Heap() color = [0] * n for v in b: color[v - 1] = 1 H.add((a[v - 1], v - 1)) ans = [] while H: nowa, now = H.pop() if color[now] == 0: continue color[now] = 0 ans.append(now + 1) for to in graph[now]: if a[now] < a[to]: color[to] ^= 1 if color[to] == 1: H.add((a[to], to)) print(len(ans)) for v in ans: print(v)