結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-08-30 20:15:46 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 719 bytes |
コンパイル時間 | 136 ms |
コンパイル使用メモリ | 82,312 KB |
実行使用メモリ | 849,056 KB |
最終ジャッジ日時 | 2024-11-24 03:04:19 |
合計ジャッジ時間 | 22,023 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 6 WA * 29 TLE * 3 |
ソースコード
import sysimport io, osinput = io.BytesIO(os.read(0,os.fstat(0).st_size)).readlinen, m = map(int, input().split())A = list(map(int, input().split()))g = [[] for i in range(n)]for i in range(m):u, v = map(int, input().split())u, v = u-1, v-1if A[u] < A[v]:g[u].append(v)elif A[u] > A[v]:g[v].append(u)k = int(input())B = list(map(int, input().split()))B = [b-1 for b in B]C = [0]*nfor b in B:C[b] = 1q = []import heapqfor b in B:q.append((A[b], b))ans = []while q:a, v =heapq.heappop(q)if C[v] == 0:continueans.append(v+1)for u in g[v]:C[u] = 1-C[u]q.append((A[u], u))print(len(ans))print(*ans, sep='\n')