<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>maehara</author_name>
  <author_url>https://blog.hatena.ne.jp/maehara/</author_url>
  <blog_title>TM's memo</blog_title>
  <blog_url>https://tmaehara-algorithm.hatenablog.com/</blog_url>
  <categories>
  </categories>
  <description>木の頂点 $u$, $v$ について最小共通先祖 (LCA) を計算するシンプルなアルゴリズムを紹介します．複数の頂点の組に対して LCA を求めるのであれば，木を前処理をしてクエリあたり $O(\log n)$ なり $O(1)$ で求めるのが定石ですが，ここではそうでなく，線形時間かけて求めることを考えます．木は親ポインタ parent: &amp;[Option&lt;usize&gt;] によって与えられるとします． O(n) 時間 O(n) 空間アルゴリズム すぐに思いつくアルゴリズムは頂点に訪問済みかどうかをあらわすフラグをもたせて各頂点から親方向に走査するものでしょう．このアルゴリズムは領域の確保に…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Ftmaehara-algorithm.hatenablog.com%2Fentry%2F2021%2F11%2F17%2F040124&quot; title=&quot;Least Common Ancestor O(d) time and O(1) space - TM&amp;#39;s memo&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2021-11-17 04:01:24</published>
  <title>Least Common Ancestor O(d) time and O(1) space</title>
  <type>rich</type>
  <url>https://tmaehara-algorithm.hatenablog.com/entry/2021/11/17/040124</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
