結果
問題 | No.1477 Lamps on Graph |
ユーザー | kuro_B |
提出日時 | 2023-05-15 23:08:21 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 516 ms / 2,000 ms |
コード長 | 2,320 bytes |
コンパイル時間 | 2,057 ms |
コンパイル使用メモリ | 86,852 KB |
実行使用メモリ | 132,308 KB |
最終ジャッジ日時 | 2023-08-20 21:46:39 |
合計ジャッジ時間 | 20,720 ms |
ジャッジサーバーID (参考情報) |
judge13 / judge15 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 295 ms
94,800 KB |
testcase_01 | AC | 291 ms
94,696 KB |
testcase_02 | AC | 290 ms
94,728 KB |
testcase_03 | AC | 291 ms
94,804 KB |
testcase_04 | AC | 286 ms
95,056 KB |
testcase_05 | AC | 290 ms
94,880 KB |
testcase_06 | AC | 288 ms
94,844 KB |
testcase_07 | AC | 287 ms
94,668 KB |
testcase_08 | AC | 293 ms
94,748 KB |
testcase_09 | AC | 297 ms
95,008 KB |
testcase_10 | AC | 296 ms
94,912 KB |
testcase_11 | AC | 290 ms
94,828 KB |
testcase_12 | AC | 458 ms
110,016 KB |
testcase_13 | AC | 432 ms
112,288 KB |
testcase_14 | AC | 465 ms
114,680 KB |
testcase_15 | AC | 396 ms
105,064 KB |
testcase_16 | AC | 378 ms
102,036 KB |
testcase_17 | AC | 373 ms
101,636 KB |
testcase_18 | AC | 421 ms
121,272 KB |
testcase_19 | AC | 415 ms
110,232 KB |
testcase_20 | AC | 387 ms
101,912 KB |
testcase_21 | AC | 402 ms
116,804 KB |
testcase_22 | AC | 362 ms
101,060 KB |
testcase_23 | AC | 420 ms
107,156 KB |
testcase_24 | AC | 494 ms
120,556 KB |
testcase_25 | AC | 392 ms
104,024 KB |
testcase_26 | AC | 463 ms
116,468 KB |
testcase_27 | AC | 408 ms
106,424 KB |
testcase_28 | AC | 423 ms
107,476 KB |
testcase_29 | AC | 411 ms
107,064 KB |
testcase_30 | AC | 352 ms
109,244 KB |
testcase_31 | AC | 385 ms
102,968 KB |
testcase_32 | AC | 448 ms
132,308 KB |
testcase_33 | AC | 449 ms
128,276 KB |
testcase_34 | AC | 425 ms
126,160 KB |
testcase_35 | AC | 514 ms
121,640 KB |
testcase_36 | AC | 516 ms
122,020 KB |
testcase_37 | AC | 496 ms
119,572 KB |
testcase_38 | AC | 508 ms
119,796 KB |
testcase_39 | AC | 511 ms
121,864 KB |
ソースコード
###スニペット始まり### import sys, re from copy import copy, deepcopy from math import ceil, floor, sqrt,factorial, gcd, pi, degrees, radians, sin, asin, cos, acos, tan, atan2 from statistics import mean, median from collections import Counter, deque, defaultdict from heapq import heapify, heappop, heappush from itertools import permutations, accumulate, product, combinations, combinations_with_replacement from bisect import bisect, bisect_left, bisect_right from functools import reduce, lru_cache from string import ascii_uppercase, ascii_lowercase from decimal import Decimal, ROUND_HALF_UP #四捨五入用 def input(): return sys.stdin.readline().rstrip('\n') #easy-testのpypyでは再帰数を下げる。 if __file__=='prog.py': sys.setrecursionlimit(10**5) else: sys.setrecursionlimit(10**6) def lcm(a, b): return a * b // gcd(a, b) #3つ以上の最大公約数/最小公倍数。Nを要素数、Mを数値の大きさとして、O(NlogM) def gcd_v2(l: list): return reduce(gcd, l) def lcm_v2(l: list): return reduce(lcm, l) #nPk def nPk(n, k): return factorial(n) // factorial(n - k) #逆元 def modinv(a, mod=10**9+7): return pow(a, mod-2, mod) INF = float('inf') MOD = 10 ** 9 + 7 ###スニペット終わり### N, M=map(int, input().split()) A=list(map(int, input().split())) es=[] for _ in range(M): a, b = map(int, input().split()) es.append([a,b]) K=int(input()) B=list(map(int, input().split())) lamps=[0]*N #0がoff、1がon for b in B: lamps[b-1]=1 graph = [[] for _ in range(N)] input_edge=[0]*N for i in range(M): a,b=es[i] if A[a-1]<A[b-1]: graph[a-1].append(b-1) input_edge[b-1]+=1 elif A[a-1]>A[b-1]: graph[b-1].append(a-1) input_edge[a-1]+=1 ans = [] que=deque([i for i in range(N) if input_edge[i] == 0]) while que: q = que.popleft() if not lamps[q]: for e in graph[q]: input_edge[e] -= 1 if input_edge[e] == 0: que.append(e) else: #切り替えする。 lamps[q]=0 #消す。 ans.append(q) for e in graph[q]: input_edge[e] -= 1 lamps[e]=0 if lamps[e]==1 else 1 if input_edge[e] == 0: que.append(e) print(len(ans)) for a in ans: print(a+1)