結果

問題 No.1477 Lamps on Graph
ユーザー kuro_Bkuro_B
提出日時 2023-05-15 22:21:07
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 2,159 bytes
コンパイル時間 210 ms
コンパイル使用メモリ 82,208 KB
実行使用メモリ 119,368 KB
最終ジャッジ日時 2024-05-08 03:42:29
合計ジャッジ時間 17,050 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 131 ms
82,692 KB
testcase_01 AC 132 ms
82,460 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 AC 132 ms
82,764 KB
testcase_05 WA -
testcase_06 AC 137 ms
82,512 KB
testcase_07 WA -
testcase_08 AC 128 ms
82,520 KB
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 AC 253 ms
119,368 KB
testcase_35 WA -
testcase_36 WA -
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

###スニペット始まり###
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)
        if lamps[a-1]:
            input_edge[b-1]+=1
    elif A[a-1]>A[b-1]:
        graph[b-1].append(a-1)  
        if lamps[b-1]:
            input_edge[b-1]+=1

ans = [i for i in range(N) if input_edge[i] == 0 and lamps[i]==1]
que=deque(ans)
while que:
    q = que.popleft()
    for e in graph[q]:
        input_edge[e] -= 1
        lamps[e]=0 if lamps[e]==1 else 0
        if input_edge[e] == 0 and lamps[e]==1:
            que.append(e)
            ans.append(e)
print(len(ans))
for a in ans:
    print(a+1)
0