Haskell, 106102 bytes
Port of my BQN answer, takes the number of vertices on the left.
import Data.List n!([u,v]:e)=zipWith(-)(n!e)$0:(tail n-1)!nub[sort$take 2$(r++[v])\\[u]|r<-e] n!_=1:(0<$[1..n]0<$n) I feel like there should be a shorter way to replace \$u\$ with \$v\$ in a list (currently take 2$(r++[v])\\[u]).