結果
問題 | No.1477 Lamps on Graph |
ユーザー | mkawa2 |
提出日時 | 2021-04-16 21:21:29 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
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 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 36 ms
11,008 KB |
testcase_01 | AC | 35 ms
10,752 KB |
testcase_02 | AC | 34 ms
10,880 KB |
testcase_03 | AC | 30 ms
10,752 KB |
testcase_04 | AC | 30 ms
10,752 KB |
testcase_05 | AC | 30 ms
10,752 KB |
testcase_06 | AC | 31 ms
10,752 KB |
testcase_07 | AC | 30 ms
11,008 KB |
testcase_08 | AC | 30 ms
10,752 KB |
testcase_09 | AC | 31 ms
10,880 KB |
testcase_10 | AC | 31 ms
10,880 KB |
testcase_11 | AC | 31 ms
10,752 KB |
testcase_12 | AC | 346 ms
23,852 KB |
testcase_13 | AC | 315 ms
25,408 KB |
testcase_14 | AC | 415 ms
26,352 KB |
testcase_15 | AC | 220 ms
16,504 KB |
testcase_16 | AC | 123 ms
18,180 KB |
testcase_17 | AC | 121 ms
17,788 KB |
testcase_18 | AC | 293 ms
33,752 KB |
testcase_19 | AC | 282 ms
25,532 KB |
testcase_20 | AC | 139 ms
15,232 KB |
testcase_21 | AC | 248 ms
30,712 KB |
testcase_22 | AC | 111 ms
12,928 KB |
testcase_23 | AC | 271 ms
17,664 KB |
testcase_24 | AC | 466 ms
31,600 KB |
testcase_25 | AC | 178 ms
16,384 KB |
testcase_26 | AC | 418 ms
31,604 KB |
testcase_27 | AC | 245 ms
17,848 KB |
testcase_28 | AC | 270 ms
21,756 KB |
testcase_29 | AC | 265 ms
20,300 KB |
testcase_30 | AC | 152 ms
24,860 KB |
testcase_31 | AC | 131 ms
19,840 KB |
testcase_32 | AC | 495 ms
40,488 KB |
testcase_33 | AC | 459 ms
38,696 KB |
testcase_34 | AC | 443 ms
38,400 KB |
testcase_35 | AC | 613 ms
38,000 KB |
testcase_36 | AC | 638 ms
37,748 KB |
testcase_37 | AC | 563 ms
33,796 KB |
testcase_38 | AC | 565 ms
35,108 KB |
testcase_39 | AC | 574 ms
37,776 KB |
ソースコード
import sys # sys.setrecursionlimit(10**6) int1 = lambda x: int(x)-1 p2D = 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**16 md = 998244353 # md = 10**9+7 n, m = LI() aa = LI() to = [[] for _ in range(n)] for _ in range(m): u, v = LI1() if aa[u] == aa[v]: continue if aa[u] > aa[v]: u, v = v, u to[u].append(v) topo = [] fin = [False]*n def dfs(u): fin[u] = True for v in to[u]: if fin[v]: continue dfs(v) topo.append(u) for u in range(n): if fin[u]: continue dfs(u) k = II() bb = LI1() dp = [False]*n for b in bb: dp[b] = True ans = [] 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")