結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-04-16 21:21:29 |
言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) |
結果 |
AC
|
実行時間 | 638 ms / 2,000 ms |
コード長 | 1,390 bytes |
コンパイル時間 | 332 ms |
コンパイル使用メモリ | 12,928 KB |
実行使用メモリ | 40,488 KB |
最終ジャッジ日時 | 2024-07-03 00:39:41 |
合計ジャッジ時間 | 12,928 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
import sys# sys.setrecursionlimit(10**6)int1 = lambda x: int(x)-1p2D = lambda x: print(*x, sep="\n")def II(): return int(sys.stdin.buffer.readline())def FI(): return float(sys.stdin.buffer.readline())def LI(): return list(map(int, sys.stdin.buffer.readline().split()))def LI1(): return list(map(int1, sys.stdin.buffer.readline().split()))def LLI(rows_number): return [LI() for _ in range(rows_number)]def LLI1(rows_number): return [LI1() for _ in range(rows_number)]def BI(): return sys.stdin.buffer.readline().rstrip()def SI(): return sys.stdin.buffer.readline().rstrip().decode()# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]dij = [(0, 1), (1, 0), (1, 1), (1, -1)]inf = 10**16md = 998244353# md = 10**9+7n, m = LI()aa = LI()to = [[] for _ in range(n)]for _ in range(m):u, v = LI1()if aa[u] == aa[v]: continueif aa[u] > aa[v]: u, v = v, uto[u].append(v)topo = []fin = [False]*ndef dfs(u):fin[u] = Truefor v in to[u]:if fin[v]: continuedfs(v)topo.append(u)for u in range(n):if fin[u]: continuedfs(u)k = II()bb = LI1()dp = [False]*nfor b in bb: dp[b] = Trueans = []for u in topo[::-1]:if dp[u]:ans.append(u+1)for v in to[u]:dp[v] = not dp[v]print(len(ans))print(*ans, sep="\n")