結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-08-30 20:17:45 |
言語 | PyPy3 (7.3.15) |
結果 |
WA
|
実行時間 | - |
コード長 | 772 bytes |
コンパイル時間 | 388 ms |
コンパイル使用メモリ | 82,304 KB |
実行使用メモリ | 956,468 KB |
最終ジャッジ日時 | 2024-11-24 03:07:59 |
合計ジャッジ時間 | 24,491 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 8 WA * 26 TLE * 3 MLE * 1 |
ソースコード
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:continueC[v] = 0ans.append(v+1)for u in g[v]:C[u] = 1-C[u]q.append((A[u], u))if sum(C) > 0:print(-1)exit()print(len(ans))print(*ans, sep='\n')