"""Exact first classification of profile feasibility with an 11-cycle quotient. Small-root cycle values are matched in mu_6, preserving multiplicities. The 11-component of the phase at a cycle is a vertex label in Z/11. An edge from a left cycle to a right cycle has label right-left. These 11 labels must be distinct. Parallel edges are therefore impossible. """ from itertools import combinations_with_replacement, permutations, product from collections import Counter, defaultdict from pathlib import Path import json, time ROOT=Path(__file__).resolve().parent P={'E':(3,3,3,2),'F':(3,2,2,2,2)} def configs(shape): groups=[] for p in sorted(set(shape),reverse=True): opts=[tuple((a+6*k//p)%6 for k in range(p)) for a in range(6//p)] groups.append(list(combinations_with_replacement(opts,shape.count(p)))) return [tuple(c for g in parts for c in g) for parts in product(*groups)] def multiplicities(config): return tuple(sum(r in c for c in config) for r in range(6)) def shifted(config,t): groups=defaultdict(list) for c in config: groups[len(c)].append(tuple(sorted((r+t)%6 for r in c))) return tuple(c for p in sorted(groups,reverse=True) for c in sorted(groups[p])) def normalized_pair(a,b): return min((shifted(a,t),shifted(b,t)) for t in range(6)) def column_perms(shape): groups=[[i for i,s in enumerate(shape) if s==p] for p in sorted(set(shape),reverse=True)] return [tuple(i for group in choice for i in group) for choice in product(*(list(permutations(g)) for g in groups))] def canonical_graph(edges, left_shape, right_shape): best=None; best_edges=None for columns in column_perms(right_shape): ci={old:new for new,old in enumerate(columns)} masks=[sum(1<>d&1:return None mask|=1<=L else -len(adj[y]))*values[y] for y in range(V) if y!=x) coeff=len(adj[x]) if x>=L else -len(adj[x]) domain=[(-total*pow(coeff%11,-1,11))%11] for value in domain: m=mask for y in adj[x]: if values[y] is None: continue d=(value-values[y])%11 if x>=L else (values[y]-value)%11 if m>>d&1:break m|=1<