pan>
        <span class="c1"># Get the path to the root from each </span>
        <span class="n">anc_u</span> <span class="o">=</span> <span class="nb">set</span><span class="p">(</span><span class="n">nx</span><span class="o">.</span><span class="n">shortest_path</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">u</span><span class="p">,</span> <span class="s1">&#39;v_inf&#39;</span><span class="p">))</span>
        <span class="n">anc_v</span> <span class