00-圆方树-02-边栈与封口.svg 2.3 KB

123456789101112131415
  1. <svg xmlns="http://www.w3.org/2000/svg" width="940" height="360" viewBox="0 0 940 360">
  2. <style>.t{font:16px sans-serif;fill:#1f2937}.s{font:13px sans-serif;fill:#475569}.n{fill:white;stroke:#2563eb;stroke-width:3}.tree{stroke:#2563eb;stroke-width:4}.back{stroke:#f97316;stroke-width:3;stroke-dasharray:8 6;fill:none}.card{fill:#fff7ed;stroke:#f97316;stroke-width:2}.stack{fill:#ecfeff;stroke:#0891b2;stroke-width:3}</style>
  3. <rect width="940" height="360" fill="#f8fafc"/><text x="35" y="34" class="t" font-weight="bold">边栈:一段 DFS 子树再也绕不到父亲上方时,整批走廊结账</text>
  4. <g class="tree"><line x1="120" y1="90" x2="230" y2="160"/><line x1="230" y1="160" x2="340" y2="235"/><line x1="340" y1="235" x2="445" y2="305"/><line x1="230" y1="160" x2="340" y2="85"/><line x1="340" y1="85" x2="445" y2="155"/></g>
  5. <path d="M445 155 Q360 205 230 160" class="back"/><path d="M445 305 Q340 335 230 160" class="back"/>
  6. <g class="n"><circle cx="120" cy="90" r="20"/><circle cx="230" cy="160" r="20"/><circle cx="340" cy="235" r="20"/><circle cx="445" cy="305" r="20"/><circle cx="340" cy="85" r="20"/><circle cx="445" cy="155" r="20"/></g>
  7. <g class="t" text-anchor="middle"><text x="120" y="96">A</text><text x="230" y="166">C</text><text x="340" y="241">F</text><text x="445" y="311">G</text><text x="340" y="91">D</text><text x="445" y="161">E</text></g>
  8. <text x="56" y="340" class="s">蓝实线=树边;橙虚线=返祖边。F-G 没有虚线旁路,先封成一个块。</text>
  9. <line x1="535" y1="56" x2="535" y2="332" stroke="#cbd5e1" stroke-width="2"/>
  10. <text x="580" y="84" class="t" font-weight="bold">栈顶</text>
  11. <rect x="580" y="102" width="250" height="42" rx="7" class="card"/><text x="598" y="129" class="t">F-G</text><text x="705" y="129" class="s">low[G] &gt; dfn[F]</text>
  12. <rect x="580" y="150" width="250" height="42" rx="7" class="card"/><text x="598" y="177" class="t">C-F</text><text x="705" y="177" class="s">随后 low[F] &gt; dfn[C]</text>
  13. <rect x="580" y="198" width="250" height="42" rx="7" class="stack"/><text x="598" y="225" class="t">C-D, D-E, E-C</text><text x="598" y="258" class="s">low[D] = dfn[C],三角形一起弹出</text>
  14. <text x="580" y="305" class="s">每条边只进栈、出栈一次;方点就在一次弹栈时出生。</text>
  15. </svg>