結果
問題 | No.1477 Lamps on Graph |
ユーザー |
![]() |
提出日時 | 2021-04-16 20:43:37 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 252 ms / 2,000 ms |
コード長 | 1,149 bytes |
コンパイル時間 | 483 ms |
コンパイル使用メモリ | 82,176 KB |
実行使用メモリ | 113,888 KB |
最終ジャッジ日時 | 2024-07-02 23:14:42 |
合計ジャッジ時間 | 7,408 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 |
other | AC * 38 |
ソースコード
import sys,math,itertoolsfrom collections import Counter,deque,defaultdictfrom bisect import bisect_left,bisect_rightfrom heapq import heappop,heappush,heapifymod = 10**9+7INF = float('inf')def inp(): return int(sys.stdin.readline())def inpl(): return list(map(int, sys.stdin.readline().split()))def inpl_1(): return list(map(lambda x:int(x)-1, sys.stdin.readline().split()))def inps(): return sys.stdin.readline()def inpsl(x): tmp = sys.stdin.readline(); return list(tmp[:x])def err(x): print(x); exit()n,m = inpl()a = inpl()g = [[] for _ in range(n)]ny = [0]*nfor _ in range(m):u,v = inpl_1()if a[u] == a[v]: continueif a[u] > a[v]: u,v = v,ug[u].append(v)ny[v] += 1k = inp()b = [0]*nfor x in inpl():b[x-1] = 1q = deque([])seen = [0]*nres = []for i,x in enumerate(ny):if x == 0:q.append(i)seen[i] = 1while q:u = q.popleft()if b[u]:res.append(u+1)for v in g[u]:if seen[v]: continueb[v] ^= b[u]ny[v] -= 1if ny[v] == 0:q.append(v)seen[v] = 1print(len(res))for x in res:print(x)