Documentation for 8b1eab204b

This commit is contained in:
realstealthninja
2024-11-04 12:43:05 +00:00
parent 4fb6e622e9
commit a7bccf7d01
6732 changed files with 153919 additions and 365711 deletions

View File

@@ -1,3 +1,4 @@
<!-- HTML header for doxygen 1.12.0-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
@@ -5,10 +6,15 @@
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>Algorithms_in_C++: graph/lowest_common_ancestor.cpp File Reference</title>
<title>TheAlgorithms/C++: graph/lowest_common_ancestor.cpp File Reference</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
@@ -18,14 +24,24 @@
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.7/MathJax.js?config=TeX-MML-AM_CHTML/MathJax.js"></script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
@@ -33,10 +49,11 @@ MathJax.Hub.Config({
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of algorithms implemented in C++.</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
@@ -124,7 +141,9 @@ Include dependency graph for lowest_common_ancestor.cpp:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../db/d8e/lowest__common__ancestor_8cpp__incl.svg" width="410" height="126"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div><table class="memberdecls">
</div>
<p><a href="../../de/dde/lowest__common__ancestor_8cpp_source.html">Go to the source code of this file.</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="nested-classes" name="nested-classes"></a>
Classes</h2></td></tr>
<tr class="memitem:"><td class="memItemLeft" align="right" valign="top">class &#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../dc/d61/classgraph_1_1_graph.html">graph::Graph&lt; T &gt;</a></td></tr>
@@ -170,6 +189,8 @@ Functions</h2></td></tr>
lowest_common_ancestor(0, 0) = 0 <br />
lowest_common_ancestor(8, 2) = 6</p>
<p>The query is symmetrical, therefore lowest_common_ancestor(x, y) = lowest_common_ancestor(y, x) </p>
<p class="definition">Definition in file <a class="el" href="../../de/dde/lowest__common__ancestor_8cpp_source.html">lowest_common_ancestor.cpp</a>.</p>
</div><h2 class="groupheader">Function Documentation</h2>
<a id="ae66f6b31b5ad750f1fe042a706a4e3d4" name="ae66f6b31b5ad750f1fe042a706a4e3d4"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ae66f6b31b5ad750f1fe042a706a4e3d4">&#9670;&#160;</a></span>main()</h2>
@@ -186,17 +207,14 @@ Functions</h2></td></tr>
</table>
</div><div class="memdoc">
<p>Main function </p>
<p class="definition">Definition at line <a class="el" href="../../de/dde/lowest__common__ancestor_8cpp_source.html#l00255">255</a> of file <a class="el" href="../../de/dde/lowest__common__ancestor_8cpp_source.html">lowest_common_ancestor.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 255</span> {</div>
<div class="line"><span class="lineno"> 256</span> <a class="code hl_function" href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>();</div>
<div class="line"><span class="lineno"> 257</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><span class="lineno"> 258</span>}</div>
<div class="ttc" id="alowest__common__ancestor_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdef"><b>Definition</b> lowest_common_ancestor.cpp:234</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../de/dde/lowest__common__ancestor_8cpp_ae66f6b31b5ad750f1fe042a706a4e3d4_cgraph.svg" width="542" height="52"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
<div class="ttc" id="alowest__common__ancestor_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdef"><b>Definition</b> <a href="../../de/dde/lowest__common__ancestor_8cpp_source.html#l00234">lowest_common_ancestor.cpp:234</a></div></div>
</div><!-- fragment -->
</div>
</div>
<a id="a483bb8ccf42aaf7375a83e91490eda1e" name="a483bb8ccf42aaf7375a83e91490eda1e"></a>
@@ -226,17 +244,10 @@ Here is the call graph for this function:</div>
/ | \
1 6 4
</pre><p> / | / \ \ 7 5 2 8 0 | 9</p>
<div class="fragment"><div class="line"><span class="lineno"> 234</span> {<span class="comment"></span></div>
<div class="line"><span class="lineno"> 235</span><span class="comment"> /**</span></div>
<div class="line"><span class="lineno"> 236</span><span class="comment"> * _ 3 _</span></div>
<div class="line"><span class="lineno"> 237</span><span class="comment"> * / | \</span></div>
<div class="line"><span class="lineno"> 238</span><span class="comment"> * 1 6 4</span></div>
<div class="line"><span class="lineno"> 239</span><span class="comment"> * / | / \ \</span></div>
<div class="line"><span class="lineno"> 240</span><span class="comment"> * 7 5 2 8 0</span></div>
<div class="line"><span class="lineno"> 241</span><span class="comment"> * |</span></div>
<div class="line"><span class="lineno"> 242</span><span class="comment"> * 9</span></div>
<div class="line"><span class="lineno"> 243</span><span class="comment"> */</span></div>
<div class="line"><span class="lineno"> 244</span> <a class="code hl_classRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector&lt;std::pair&lt;int, int&gt;</a> &gt; edges = {</div>
<p class="definition">Definition at line <a class="el" href="../../de/dde/lowest__common__ancestor_8cpp_source.html#l00234">234</a> of file <a class="el" href="../../de/dde/lowest__common__ancestor_8cpp_source.html">lowest_common_ancestor.cpp</a>.</p>
<div class="fragment"><div class="line"><span class="lineno"> 234</span> {</div>
<div class="line"><span class="lineno"> 244</span> std::vector&lt;std::pair&lt;int, int&gt; &gt; edges = {</div>
<div class="line"><span class="lineno"> 245</span> {7, 1}, {1, 5}, {1, 3}, {3, 6}, {6, 2}, {2, 9}, {6, 8}, {4, 3}, {0, 4}};</div>
<div class="line"><span class="lineno"> 246</span> <a class="code hl_class" href="../../d0/d58/classgraph_1_1_rooted_tree.html">graph::RootedTree</a> t(edges, 3);</div>
<div class="line"><span class="lineno"> 247</span> <a class="code hl_class" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">graph::LowestCommonAncestor</a> lca(t);</div>
@@ -245,15 +256,9 @@ Here is the call graph for this function:</div>
<div class="line"><span class="lineno"> 250</span> assert(lca.lowest_common_ancestor(0, 0) == 0);</div>
<div class="line"><span class="lineno"> 251</span> assert(lca.lowest_common_ancestor(8, 2) == 6);</div>
<div class="line"><span class="lineno"> 252</span>}</div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">graph::LowestCommonAncestor</a></div><div class="ttdef"><b>Definition</b> lowest_common_ancestor.cpp:145</div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html">graph::RootedTree</a></div><div class="ttdef"><b>Definition</b> lowest_common_ancestor.cpp:84</div></div>
<div class="ttc" id="avector_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a></div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../de/dde/lowest__common__ancestor_8cpp_a483bb8ccf42aaf7375a83e91490eda1e_cgraph.svg" width="444" height="52"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">graph::LowestCommonAncestor</a></div><div class="ttdef"><b>Definition</b> <a href="../../de/dde/lowest__common__ancestor_8cpp_source.html#l00145">lowest_common_ancestor.cpp:145</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html">graph::RootedTree</a></div><div class="ttdef"><b>Definition</b> <a href="../../de/dde/lowest__common__ancestor_8cpp_source.html#l00084">lowest_common_ancestor.cpp:84</a></div></div>
</div><!-- fragment -->
</div>
</div>
</div><!-- contents -->

View File

@@ -1,7 +0,0 @@
<map id="tests" name="tests">
<area shape="rect" id="Node000001" title=" " alt="" coords="5,13,56,38"/>
<area shape="rect" id="Node000002" href="$d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488" title="Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i..." alt="" coords="104,5,312,46"/>
<area shape="poly" id="edge1_Node000001_Node000002" title=" " alt="" coords="56,23,88,23,88,28,56,28"/>
<area shape="rect" id="Node000003" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/algorithm/swap.html#" title=" " alt="" coords="360,13,438,38"/>
<area shape="poly" id="edge2_Node000002_Node000003" title=" " alt="" coords="312,23,344,23,344,28,312,28"/>
</map>

View File

@@ -1 +0,0 @@
54b78b38bedf9e4d3eb0676d2d943b9a

View File

@@ -1,84 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
-->
<!-- Title: tests Pages: 1 -->
<svg width="333pt" height="39pt"
viewBox="0.00 0.00 332.75 38.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
<style type="text/css"><![CDATA[
.node, .edge {opacity: 0.7;}
.node.selected, .edge.selected {opacity: 1;}
.edge:hover path { stroke: red; }
.edge:hover polygon { stroke: red; fill: red; }
]]></style>
<script type="application/ecmascript" xlink:href="../../svg.min.js"/>
<svg id="graph" class="graph">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 34.5)">
<title>tests</title>
<!-- Node1 -->
<g id="Node000001" class="node">
<title>Node1</title>
<g id="a_Node000001"><a xlink:title=" ">
<polygon fill="#999999" stroke="#666666" points="37.75,-24.88 0,-24.88 0,-5.63 37.75,-5.63 37.75,-24.88"/>
<text text-anchor="middle" x="18.88" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">tests</text>
</a>
</g>
</g>
<!-- Node2 -->
<g id="Node000002" class="node">
<title>Node2</title>
<g id="a_Node000002"><a xlink:href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488" target="_top" xlink:title="Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i...">
<polygon fill="white" stroke="#666666" points="230,-30.5 73.75,-30.5 73.75,0 230,0 230,-30.5"/>
<text text-anchor="start" x="81.75" y="-17" font-family="Helvetica,sans-Serif" font-size="10.00">graph::LowestCommonAncestor</text>
<text text-anchor="middle" x="151.88" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">::lowest_common_ancestor</text>
</a>
</g>
</g>
<!-- Node1&#45;&gt;Node2 -->
<g id="edge1_Node000001_Node000002" class="edge">
<title>Node1&#45;&gt;Node2</title>
<g id="a_edge1_Node000001_Node000002"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M38.09,-15.25C44.94,-15.25 53.26,-15.25 62.25,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="61.98,-18.75 71.98,-15.25 61.98,-11.75 61.98,-18.75"/>
</a>
</g>
</g>
<!-- Node3 -->
<g id="Node000003" class="node">
<title>Node3</title>
<g id="a_Node000003"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/algorithm/swap.html#" xlink:title=" ">
<polygon fill="white" stroke="#666666" points="324.75,-24.88 266,-24.88 266,-5.63 324.75,-5.63 324.75,-24.88"/>
<text text-anchor="middle" x="295.38" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">std::swap</text>
</a>
</g>
</g>
<!-- Node2&#45;&gt;Node3 -->
<g id="edge2_Node000002_Node000003" class="edge">
<title>Node2&#45;&gt;Node3</title>
<g id="a_edge2_Node000002_Node000003"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M230.25,-15.25C238.55,-15.25 246.72,-15.25 254.32,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="254.18,-18.75 264.18,-15.25 254.18,-11.75 254.18,-18.75"/>
</a>
</g>
</g>
</g>
</svg>
</svg>
<style type='text/css'>
<![CDATA[
[data-mouse-over-selected='false'] { opacity: 0.7; }
[data-mouse-over-selected='true'] { opacity: 1.0; }
]]>
</style>
<script type="application/ecmascript"><![CDATA[
document.addEventListener('DOMContentLoaded', (event) => {
highlightEdges();
highlightAdjacentNodes();
});
]]></script>
</svg>

Before

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -1,58 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
-->
<!-- Title: tests Pages: 1 -->
<svg width="333pt" height="39pt"
viewBox="0.00 0.00 332.75 38.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 34.5)">
<title>tests</title>
<!-- Node1 -->
<g id="Node000001" class="node">
<title>Node1</title>
<g id="a_Node000001"><a xlink:title=" ">
<polygon fill="#999999" stroke="#666666" points="37.75,-24.88 0,-24.88 0,-5.63 37.75,-5.63 37.75,-24.88"/>
<text text-anchor="middle" x="18.88" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">tests</text>
</a>
</g>
</g>
<!-- Node2 -->
<g id="Node000002" class="node">
<title>Node2</title>
<g id="a_Node000002"><a xlink:href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488" target="_top" xlink:title="Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i...">
<polygon fill="white" stroke="#666666" points="230,-30.5 73.75,-30.5 73.75,0 230,0 230,-30.5"/>
<text text-anchor="start" x="81.75" y="-17" font-family="Helvetica,sans-Serif" font-size="10.00">graph::LowestCommonAncestor</text>
<text text-anchor="middle" x="151.88" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">::lowest_common_ancestor</text>
</a>
</g>
</g>
<!-- Node1&#45;&gt;Node2 -->
<g id="edge1_Node000001_Node000002" class="edge">
<title>Node1&#45;&gt;Node2</title>
<g id="a_edge1_Node000001_Node000002"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M38.09,-15.25C44.94,-15.25 53.26,-15.25 62.25,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="61.98,-18.75 71.98,-15.25 61.98,-11.75 61.98,-18.75"/>
</a>
</g>
</g>
<!-- Node3 -->
<g id="Node000003" class="node">
<title>Node3</title>
<g id="a_Node000003"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/algorithm/swap.html#" xlink:title=" ">
<polygon fill="white" stroke="#666666" points="324.75,-24.88 266,-24.88 266,-5.63 324.75,-5.63 324.75,-24.88"/>
<text text-anchor="middle" x="295.38" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">std::swap</text>
</a>
</g>
</g>
<!-- Node2&#45;&gt;Node3 -->
<g id="edge2_Node000002_Node000003" class="edge">
<title>Node2&#45;&gt;Node3</title>
<g id="a_edge2_Node000002_Node000003"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M230.25,-15.25C238.55,-15.25 246.72,-15.25 254.32,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="254.18,-18.75 264.18,-15.25 254.18,-11.75 254.18,-18.75"/>
</a>
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 2.7 KiB

View File

@@ -1,9 +0,0 @@
<map id="main" name="main">
<area shape="rect" id="Node000001" title=" " alt="" coords="5,13,55,38"/>
<area shape="rect" id="Node000002" href="$de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e" title=" " alt="" coords="103,13,153,38"/>
<area shape="poly" id="edge1_Node000001_Node000002" title=" " alt="" coords="55,23,88,23,88,28,55,28"/>
<area shape="rect" id="Node000003" href="$d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488" title="Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i..." alt="" coords="201,5,409,46"/>
<area shape="poly" id="edge2_Node000002_Node000003" title=" " alt="" coords="153,23,186,23,186,28,153,28"/>
<area shape="rect" id="Node000004" href="/Users/runner/work/C-Plus-Plus/C-Plus-Plus/doc/cppreference-doxygen-web.tag.xml$cpp/algorithm/swap.html#" title=" " alt="" coords="457,13,536,38"/>
<area shape="poly" id="edge3_Node000003_Node000004" title=" " alt="" coords="410,23,442,23,442,28,410,28"/>
</map>

View File

@@ -1 +0,0 @@
a3ba2d80c6c85467300e0a5179a0f52c

View File

@@ -1,102 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
-->
<!-- Title: main Pages: 1 -->
<svg width="406pt" height="39pt"
viewBox="0.00 0.00 405.75 38.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<svg id="main" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xml:space="preserve">
<style type="text/css"><![CDATA[
.node, .edge {opacity: 0.7;}
.node.selected, .edge.selected {opacity: 1;}
.edge:hover path { stroke: red; }
.edge:hover polygon { stroke: red; fill: red; }
]]></style>
<script type="application/ecmascript" xlink:href="../../svg.min.js"/>
<svg id="graph" class="graph">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 34.5)">
<title>main</title>
<!-- Node1 -->
<g id="Node000001" class="node">
<title>Node1</title>
<g id="a_Node000001"><a xlink:title=" ">
<polygon fill="#999999" stroke="#666666" points="37,-24.88 0,-24.88 0,-5.63 37,-5.63 37,-24.88"/>
<text text-anchor="middle" x="18.5" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">main</text>
</a>
</g>
</g>
<!-- Node2 -->
<g id="Node000002" class="node">
<title>Node2</title>
<g id="a_Node000002"><a xlink:href="../../de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e" target="_top" xlink:title=" ">
<polygon fill="white" stroke="#666666" points="110.75,-24.88 73,-24.88 73,-5.63 110.75,-5.63 110.75,-24.88"/>
<text text-anchor="middle" x="91.88" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">tests</text>
</a>
</g>
</g>
<!-- Node1&#45;&gt;Node2 -->
<g id="edge1_Node000001_Node000002" class="edge">
<title>Node1&#45;&gt;Node2</title>
<g id="a_edge1_Node000001_Node000002"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M37.14,-15.25C44.55,-15.25 53.37,-15.25 61.69,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="61.43,-18.75 71.43,-15.25 61.43,-11.75 61.43,-18.75"/>
</a>
</g>
</g>
<!-- Node3 -->
<g id="Node000003" class="node">
<title>Node3</title>
<g id="a_Node000003"><a xlink:href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488" target="_top" xlink:title="Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i...">
<polygon fill="white" stroke="#666666" points="303,-30.5 146.75,-30.5 146.75,0 303,0 303,-30.5"/>
<text text-anchor="start" x="154.75" y="-17" font-family="Helvetica,sans-Serif" font-size="10.00">graph::LowestCommonAncestor</text>
<text text-anchor="middle" x="224.88" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">::lowest_common_ancestor</text>
</a>
</g>
</g>
<!-- Node2&#45;&gt;Node3 -->
<g id="edge2_Node000002_Node000003" class="edge">
<title>Node2&#45;&gt;Node3</title>
<g id="a_edge2_Node000002_Node000003"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M111.09,-15.25C117.94,-15.25 126.26,-15.25 135.25,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="134.98,-18.75 144.98,-15.25 134.98,-11.75 134.98,-18.75"/>
</a>
</g>
</g>
<!-- Node4 -->
<g id="Node000004" class="node">
<title>Node4</title>
<g id="a_Node000004"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/algorithm/swap.html#" xlink:title=" ">
<polygon fill="white" stroke="#666666" points="397.75,-24.88 339,-24.88 339,-5.63 397.75,-5.63 397.75,-24.88"/>
<text text-anchor="middle" x="368.38" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">std::swap</text>
</a>
</g>
</g>
<!-- Node3&#45;&gt;Node4 -->
<g id="edge3_Node000003_Node000004" class="edge">
<title>Node3&#45;&gt;Node4</title>
<g id="a_edge3_Node000003_Node000004"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M303.25,-15.25C311.55,-15.25 319.72,-15.25 327.32,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="327.18,-18.75 337.18,-15.25 327.18,-11.75 327.18,-18.75"/>
</a>
</g>
</g>
</g>
</svg>
</svg>
<style type='text/css'>
<![CDATA[
[data-mouse-over-selected='false'] { opacity: 0.7; }
[data-mouse-over-selected='true'] { opacity: 1.0; }
]]>
</style>
<script type="application/ecmascript"><![CDATA[
document.addEventListener('DOMContentLoaded', (event) => {
highlightEdges();
highlightAdjacentNodes();
});
]]></script>
</svg>

Before

Width:  |  Height:  |  Size: 4.3 KiB

View File

@@ -1,76 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 12.1.2 (20240928.0832)
-->
<!-- Title: main Pages: 1 -->
<svg width="406pt" height="39pt"
viewBox="0.00 0.00 405.75 38.50" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 34.5)">
<title>main</title>
<!-- Node1 -->
<g id="Node000001" class="node">
<title>Node1</title>
<g id="a_Node000001"><a xlink:title=" ">
<polygon fill="#999999" stroke="#666666" points="37,-24.88 0,-24.88 0,-5.63 37,-5.63 37,-24.88"/>
<text text-anchor="middle" x="18.5" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">main</text>
</a>
</g>
</g>
<!-- Node2 -->
<g id="Node000002" class="node">
<title>Node2</title>
<g id="a_Node000002"><a xlink:href="../../de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e" target="_top" xlink:title=" ">
<polygon fill="white" stroke="#666666" points="110.75,-24.88 73,-24.88 73,-5.63 110.75,-5.63 110.75,-24.88"/>
<text text-anchor="middle" x="91.88" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">tests</text>
</a>
</g>
</g>
<!-- Node1&#45;&gt;Node2 -->
<g id="edge1_Node000001_Node000002" class="edge">
<title>Node1&#45;&gt;Node2</title>
<g id="a_edge1_Node000001_Node000002"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M37.14,-15.25C44.55,-15.25 53.37,-15.25 61.69,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="61.43,-18.75 71.43,-15.25 61.43,-11.75 61.43,-18.75"/>
</a>
</g>
</g>
<!-- Node3 -->
<g id="Node000003" class="node">
<title>Node3</title>
<g id="a_Node000003"><a xlink:href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488" target="_top" xlink:title="Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i...">
<polygon fill="white" stroke="#666666" points="303,-30.5 146.75,-30.5 146.75,0 303,0 303,-30.5"/>
<text text-anchor="start" x="154.75" y="-17" font-family="Helvetica,sans-Serif" font-size="10.00">graph::LowestCommonAncestor</text>
<text text-anchor="middle" x="224.88" y="-5.75" font-family="Helvetica,sans-Serif" font-size="10.00">::lowest_common_ancestor</text>
</a>
</g>
</g>
<!-- Node2&#45;&gt;Node3 -->
<g id="edge2_Node000002_Node000003" class="edge">
<title>Node2&#45;&gt;Node3</title>
<g id="a_edge2_Node000002_Node000003"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M111.09,-15.25C117.94,-15.25 126.26,-15.25 135.25,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="134.98,-18.75 144.98,-15.25 134.98,-11.75 134.98,-18.75"/>
</a>
</g>
</g>
<!-- Node4 -->
<g id="Node000004" class="node">
<title>Node4</title>
<g id="a_Node000004"><a target="_blank" xlink:href="http://en.cppreference.com/w/cpp/algorithm/swap.html#" xlink:title=" ">
<polygon fill="white" stroke="#666666" points="397.75,-24.88 339,-24.88 339,-5.63 397.75,-5.63 397.75,-24.88"/>
<text text-anchor="middle" x="368.38" y="-11.38" font-family="Helvetica,sans-Serif" font-size="10.00">std::swap</text>
</a>
</g>
</g>
<!-- Node3&#45;&gt;Node4 -->
<g id="edge3_Node000003_Node000004" class="edge">
<title>Node3&#45;&gt;Node4</title>
<g id="a_edge3_Node000003_Node000004"><a xlink:title=" ">
<path fill="none" stroke="#63b8ff" d="M303.25,-15.25C311.55,-15.25 319.72,-15.25 327.32,-15.25"/>
<polygon fill="#63b8ff" stroke="#63b8ff" points="327.18,-18.75 337.18,-15.25 327.18,-11.75 327.18,-18.75"/>
</a>
</g>
</g>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 3.5 KiB

View File

@@ -0,0 +1,315 @@
<!-- HTML header for doxygen 1.12.0-->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>TheAlgorithms/C++: graph/lowest_common_ancestor.cpp Source File</title>
<link rel="icon" href="../../favicon.svg" type="image/x-icon" />
<link href="../../tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../jquery.js"></script>
<script type="text/javascript" src="../../dynsections.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/@xpack-3rd-party/doxygen-awesome-css@2.2.0-1/doxygen-awesome-darkmode-toggle.js"></script>
<script type="text/javascript">
DoxygenAwesomeDarkModeToggle.init()
</script>
<script type="text/javascript" src="../../clipboard.js"></script>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.js"></script>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../cookie.js"></script>
<link href="../../search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../search/searchdata.js"></script>
<script type="text/javascript" src="../../search/search.js"></script>
<script type="text/javascript">
window.MathJax = {
options: {
ignoreHtmlClass: 'tex2jax_ignore',
processHtmlClass: 'tex2jax_process'
},
loader: {
load: ['[tex]/ams']
},
tex: {
macros: {},
packages: ['base','configmacros','ams']
}
};
</script>
<script type="text/javascript" id="MathJax-script" async="async" src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-chtml.js"></script>
<link href="../../doxygen.css" rel="stylesheet" type="text/css" />
<link href="../../doxygen-awesome.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr id="projectrow">
<td id="projectlogo"><img alt="Logo" src="../../project_logo.png"/></td>
<td id="projectalign">
<div id="projectname">TheAlgorithms/C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">All the algorithms implemented in C++</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
var searchBox = new SearchBox("searchBox", "../../search/",'.html');
/* @license-end */
</script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(1); });
/* @license-end */
</script>
<script type="text/javascript" src="../../menudata.js"></script>
<script type="text/javascript" src="../../menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() {
initMenu('../../',true,false,'search.php','Search',true);
$(function() { init_search(); });
});
/* @license-end */
</script>
<div id="main-nav"></div>
</div><!-- top -->
<div id="side-nav" class="ui-resizable side-nav-resizable">
<div id="nav-tree">
<div id="nav-tree-contents">
<div id="nav-sync" class="sync"></div>
</div>
</div>
<div id="splitbar" style="-moz-user-select:none;"
class="ui-resizable-handle">
</div>
</div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){initNavTree('de/dde/lowest__common__ancestor_8cpp_source.html','../../'); initResizable(true); });
/* @license-end */
</script>
<div id="doc-content">
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<div id="MSearchResults">
<div class="SRPage">
<div id="SRIndex">
<div id="SRResults"></div>
<div class="SRStatus" id="Loading">Loading...</div>
<div class="SRStatus" id="Searching">Searching...</div>
<div class="SRStatus" id="NoMatches">No Matches</div>
</div>
</div>
</div>
</div>
<div class="header">
<div class="headertitle"><div class="title">lowest_common_ancestor.cpp</div></div>
</div><!--header-->
<div class="contents">
<a href="../../de/dde/lowest__common__ancestor_8cpp.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a id="l00001" name="l00001"></a><span class="lineno"> 1</span> </div>
<div class="line"><a id="l00038" name="l00038"></a><span class="lineno"> 38</span><span class="preprocessor">#include &lt;cassert&gt;</span></div>
<div class="line"><a id="l00039" name="l00039"></a><span class="lineno"> 39</span><span class="preprocessor">#include &lt;iostream&gt;</span></div>
<div class="line"><a id="l00040" name="l00040"></a><span class="lineno"> 40</span><span class="preprocessor">#include &lt;queue&gt;</span></div>
<div class="line"><a id="l00041" name="l00041"></a><span class="lineno"> 41</span><span class="preprocessor">#include &lt;utility&gt;</span></div>
<div class="line"><a id="l00042" name="l00042"></a><span class="lineno"> 42</span><span class="preprocessor">#include &lt;vector&gt;</span></div>
<div class="line"><a id="l00043" name="l00043"></a><span class="lineno"> 43</span> </div>
<div class="line"><a id="l00048" name="l00048"></a><span class="lineno"> 48</span><span class="keyword">namespace </span><a class="code hl_namespace" href="../../df/dce/namespacegraph.html">graph</a> {</div>
<div class="foldopen" id="foldopen00053" data-start="{" data-end="};">
<div class="line"><a id="l00053" name="l00053"></a><span class="lineno"><a class="line" href="../../dc/d61/classgraph_1_1_graph.html"> 53</a></span><span class="keyword">class </span><a class="code hl_class" href="../../dc/d61/classgraph_1_1_graph.html">Graph</a> {</div>
<div class="line"><a id="l00054" name="l00054"></a><span class="lineno"> 54</span> <span class="keyword">public</span>:</div>
<div class="foldopen" id="foldopen00062" data-start="{" data-end="}">
<div class="line"><a id="l00062" name="l00062"></a><span class="lineno"><a class="line" href="../../dc/d61/classgraph_1_1_graph.html#a8839fa14bff19d2deab4a618447c13e5"> 62</a></span> <a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8839fa14bff19d2deab4a618447c13e5">Graph</a>(<span class="keywordtype">size_t</span> N, <span class="keyword">const</span> std::vector&lt;std::pair&lt;int, int&gt; &gt; &amp;undirected_edges) {</div>
<div class="line"><a id="l00063" name="l00063"></a><span class="lineno"> 63</span> <a class="code hl_variable" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">neighbors</a>.resize(N);</div>
<div class="line"><a id="l00064" name="l00064"></a><span class="lineno"> 64</span> <span class="keywordflow">for</span> (<span class="keyword">auto</span> &amp;edge : undirected_edges) {</div>
<div class="line"><a id="l00065" name="l00065"></a><span class="lineno"> 65</span> <a class="code hl_variable" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">neighbors</a>[edge.first].push_back(edge.second);</div>
<div class="line"><a id="l00066" name="l00066"></a><span class="lineno"> 66</span> <a class="code hl_variable" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">neighbors</a>[edge.second].push_back(edge.first);</div>
<div class="line"><a id="l00067" name="l00067"></a><span class="lineno"> 67</span> }</div>
<div class="line"><a id="l00068" name="l00068"></a><span class="lineno"> 68</span> }</div>
</div>
<div class="line"><a id="l00069" name="l00069"></a><span class="lineno"> 69</span> </div>
<div class="line"><a id="l00074" name="l00074"></a><span class="lineno"><a class="line" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904"> 74</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>()<span class="keyword"> const </span>{ <span class="keywordflow">return</span> <a class="code hl_variable" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">neighbors</a>.size(); }</div>
<div class="line"><a id="l00075" name="l00075"></a><span class="lineno"> 75</span> </div>
<div class="line"><a id="l00077" name="l00077"></a><span class="lineno"><a class="line" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a"> 77</a></span> std::vector&lt;std::vector&lt;int&gt; &gt; <a class="code hl_variable" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">neighbors</a>;</div>
<div class="line"><a id="l00078" name="l00078"></a><span class="lineno"> 78</span>};</div>
</div>
<div class="line"><a id="l00079" name="l00079"></a><span class="lineno"> 79</span> </div>
<div class="foldopen" id="foldopen00084" data-start="{" data-end="};">
<div class="line"><a id="l00084" name="l00084"></a><span class="lineno"><a class="line" href="../../d0/d58/classgraph_1_1_rooted_tree.html"> 84</a></span><span class="keyword">class </span><a class="code hl_class" href="../../d0/d58/classgraph_1_1_rooted_tree.html">RootedTree</a> : <span class="keyword">public</span> <a class="code hl_class" href="../../dc/d61/classgraph_1_1_graph.html">Graph</a> {</div>
<div class="line"><a id="l00085" name="l00085"></a><span class="lineno"> 85</span> <span class="keyword">public</span>:</div>
<div class="foldopen" id="foldopen00093" data-start="{" data-end="}">
<div class="line"><a id="l00093" name="l00093"></a><span class="lineno"><a class="line" href="../../d0/d58/classgraph_1_1_rooted_tree.html#aacdeecac857623e9fbfe92590f3c504d"> 93</a></span> <a class="code hl_function" href="../../d0/d58/classgraph_1_1_rooted_tree.html#aacdeecac857623e9fbfe92590f3c504d">RootedTree</a>(<span class="keyword">const</span> std::vector&lt;std::pair&lt;int, int&gt; &gt; &amp;undirected_edges,</div>
<div class="line"><a id="l00094" name="l00094"></a><span class="lineno"> 94</span> <span class="keywordtype">int</span> root_)</div>
<div class="line"><a id="l00095" name="l00095"></a><span class="lineno"> 95</span> : <a class="code hl_class" href="../../dc/d61/classgraph_1_1_graph.html">Graph</a>(undirected_edges.size() + 1, undirected_edges), <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">root</a>(root_) {</div>
<div class="line"><a id="l00096" name="l00096"></a><span class="lineno"> 96</span> <a class="code hl_function" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ae6928f3ebd491541e9570e746b877c1e">populate_parents</a>();</div>
<div class="line"><a id="l00097" name="l00097"></a><span class="lineno"> 97</span> }</div>
</div>
<div class="line"><a id="l00098" name="l00098"></a><span class="lineno"> 98</span> </div>
<div class="line"><a id="l00104" name="l00104"></a><span class="lineno"><a class="line" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43"> 104</a></span> std::vector&lt;int&gt; <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>;</div>
<div class="line"><a id="l00106" name="l00106"></a><span class="lineno"><a class="line" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3"> 106</a></span> std::vector&lt;int&gt; <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>;</div>
<div class="line"><a id="l00108" name="l00108"></a><span class="lineno"><a class="line" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe"> 108</a></span> <span class="keywordtype">int</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">root</a>;</div>
<div class="line"><a id="l00109" name="l00109"></a><span class="lineno"> 109</span> </div>
<div class="line"><a id="l00110" name="l00110"></a><span class="lineno"> 110</span> <span class="keyword">protected</span>:</div>
<div class="foldopen" id="foldopen00117" data-start="{" data-end="}">
<div class="line"><a id="l00117" name="l00117"></a><span class="lineno"><a class="line" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ae6928f3ebd491541e9570e746b877c1e"> 117</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ae6928f3ebd491541e9570e746b877c1e">populate_parents</a>() {</div>
<div class="line"><a id="l00118" name="l00118"></a><span class="lineno"> 118</span> <span class="comment">// Initialize the vector with -1 which indicates the vertex</span></div>
<div class="line"><a id="l00119" name="l00119"></a><span class="lineno"> 119</span> <span class="comment">// wasn&#39;t yet visited.</span></div>
<div class="line"><a id="l00120" name="l00120"></a><span class="lineno"> 120</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a> = std::vector&lt;int&gt;(<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>(), -1);</div>
<div class="line"><a id="l00121" name="l00121"></a><span class="lineno"> 121</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a> = std::vector&lt;int&gt;(<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>());</div>
<div class="line"><a id="l00122" name="l00122"></a><span class="lineno"> 122</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>[<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">root</a>] = <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">root</a>;</div>
<div class="line"><a id="l00123" name="l00123"></a><span class="lineno"> 123</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">root</a>] = 0;</div>
<div class="line"><a id="l00124" name="l00124"></a><span class="lineno"> 124</span> std::queue&lt;int&gt; queue_of_vertices;</div>
<div class="line"><a id="l00125" name="l00125"></a><span class="lineno"> 125</span> queue_of_vertices.push(<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">root</a>);</div>
<div class="line"><a id="l00126" name="l00126"></a><span class="lineno"> 126</span> <span class="keywordflow">while</span> (!queue_of_vertices.empty()) {</div>
<div class="line"><a id="l00127" name="l00127"></a><span class="lineno"> 127</span> <span class="keywordtype">int</span> vertex = queue_of_vertices.front();</div>
<div class="line"><a id="l00128" name="l00128"></a><span class="lineno"> 128</span> queue_of_vertices.pop();</div>
<div class="line"><a id="l00129" name="l00129"></a><span class="lineno"> 129</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> neighbor : <a class="code hl_variable" href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">neighbors</a>[vertex]) {</div>
<div class="line"><a id="l00130" name="l00130"></a><span class="lineno"> 130</span> <span class="comment">// As long as the vertex was not yet visited.</span></div>
<div class="line"><a id="l00131" name="l00131"></a><span class="lineno"> 131</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>[neighbor] == -1) {</div>
<div class="line"><a id="l00132" name="l00132"></a><span class="lineno"> 132</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>[neighbor] = vertex;</div>
<div class="line"><a id="l00133" name="l00133"></a><span class="lineno"> 133</span> <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[neighbor] = <a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[vertex] + 1;</div>
<div class="line"><a id="l00134" name="l00134"></a><span class="lineno"> 134</span> queue_of_vertices.push(neighbor);</div>
<div class="line"><a id="l00135" name="l00135"></a><span class="lineno"> 135</span> }</div>
<div class="line"><a id="l00136" name="l00136"></a><span class="lineno"> 136</span> }</div>
<div class="line"><a id="l00137" name="l00137"></a><span class="lineno"> 137</span> }</div>
<div class="line"><a id="l00138" name="l00138"></a><span class="lineno"> 138</span> }</div>
</div>
<div class="line"><a id="l00139" name="l00139"></a><span class="lineno"> 139</span>};</div>
</div>
<div class="line"><a id="l00140" name="l00140"></a><span class="lineno"> 140</span> </div>
<div class="foldopen" id="foldopen00145" data-start="{" data-end="};">
<div class="line"><a id="l00145" name="l00145"></a><span class="lineno"><a class="line" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html"> 145</a></span><span class="keyword">class </span><a class="code hl_class" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">LowestCommonAncestor</a> {</div>
<div class="line"><a id="l00146" name="l00146"></a><span class="lineno"> 146</span> <span class="keyword">public</span>:</div>
<div class="foldopen" id="foldopen00151" data-start="{" data-end="}">
<div class="line"><a id="l00151" name="l00151"></a><span class="lineno"><a class="line" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a80825a4fd4c41860b689d253dd2c8e93"> 151</a></span> <span class="keyword">explicit</span> <a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a80825a4fd4c41860b689d253dd2c8e93">LowestCommonAncestor</a>(<span class="keyword">const</span> <a class="code hl_class" href="../../d0/d58/classgraph_1_1_rooted_tree.html">RootedTree</a> &amp;tree_) : tree(tree_) {</div>
<div class="line"><a id="l00152" name="l00152"></a><span class="lineno"> 152</span> <a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a42589cc39d6bbff6c997152f1b96e356">populate_up</a>();</div>
<div class="line"><a id="l00153" name="l00153"></a><span class="lineno"> 153</span> }</div>
</div>
<div class="line"><a id="l00154" name="l00154"></a><span class="lineno"> 154</span> </div>
<div class="foldopen" id="foldopen00164" data-start="{" data-end="}">
<div class="line"><a id="l00164" name="l00164"></a><span class="lineno"><a class="line" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488"> 164</a></span> <span class="keywordtype">int</span> <a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">lowest_common_ancestor</a>(<span class="keywordtype">int</span> u, <span class="keywordtype">int</span> v)<span class="keyword"> const </span>{</div>
<div class="line"><a id="l00165" name="l00165"></a><span class="lineno"> 165</span> <span class="comment">// Ensure u is the deeper (higher level) of the two vertices</span></div>
<div class="line"><a id="l00166" name="l00166"></a><span class="lineno"> 166</span> <span class="keywordflow">if</span> (tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[v] &gt; tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[u]) {</div>
<div class="line"><a id="l00167" name="l00167"></a><span class="lineno"> 167</span> std::swap(u, v);</div>
<div class="line"><a id="l00168" name="l00168"></a><span class="lineno"> 168</span> }</div>
<div class="line"><a id="l00169" name="l00169"></a><span class="lineno"> 169</span> </div>
<div class="line"><a id="l00170" name="l00170"></a><span class="lineno"> 170</span> <span class="comment">// &quot;Lift&quot; u to the same level as v.</span></div>
<div class="line"><a id="l00171" name="l00171"></a><span class="lineno"> 171</span> <span class="keywordtype">int</span> level_diff = tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[u] - tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[v];</div>
<div class="line"><a id="l00172" name="l00172"></a><span class="lineno"> 172</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = 0; (1 &lt;&lt; i) &lt;= level_diff; ++i) {</div>
<div class="line"><a id="l00173" name="l00173"></a><span class="lineno"> 173</span> <span class="keywordflow">if</span> (level_diff &amp; (1 &lt;&lt; i)) {</div>
<div class="line"><a id="l00174" name="l00174"></a><span class="lineno"> 174</span> u = <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i];</div>
<div class="line"><a id="l00175" name="l00175"></a><span class="lineno"> 175</span> }</div>
<div class="line"><a id="l00176" name="l00176"></a><span class="lineno"> 176</span> }</div>
<div class="line"><a id="l00177" name="l00177"></a><span class="lineno"> 177</span> assert(tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[u] == tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[v]);</div>
<div class="line"><a id="l00178" name="l00178"></a><span class="lineno"> 178</span> </div>
<div class="line"><a id="l00179" name="l00179"></a><span class="lineno"> 179</span> <span class="keywordflow">if</span> (u == v) {</div>
<div class="line"><a id="l00180" name="l00180"></a><span class="lineno"> 180</span> <span class="keywordflow">return</span> u;</div>
<div class="line"><a id="l00181" name="l00181"></a><span class="lineno"> 181</span> }</div>
<div class="line"><a id="l00182" name="l00182"></a><span class="lineno"> 182</span> </div>
<div class="line"><a id="l00183" name="l00183"></a><span class="lineno"> 183</span> <span class="comment">// &quot;Lift&quot; u and v to their 2^i th ancestor if they are different</span></div>
<div class="line"><a id="l00184" name="l00184"></a><span class="lineno"> 184</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> i = <span class="keyword">static_cast&lt;</span><span class="keywordtype">int</span><span class="keyword">&gt;</span>(<a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u].size()) - 1; i &gt;= 0; --i) {</div>
<div class="line"><a id="l00185" name="l00185"></a><span class="lineno"> 185</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i] != <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][i]) {</div>
<div class="line"><a id="l00186" name="l00186"></a><span class="lineno"> 186</span> u = <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i];</div>
<div class="line"><a id="l00187" name="l00187"></a><span class="lineno"> 187</span> v = <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][i];</div>
<div class="line"><a id="l00188" name="l00188"></a><span class="lineno"> 188</span> }</div>
<div class="line"><a id="l00189" name="l00189"></a><span class="lineno"> 189</span> }</div>
<div class="line"><a id="l00190" name="l00190"></a><span class="lineno"> 190</span> </div>
<div class="line"><a id="l00191" name="l00191"></a><span class="lineno"> 191</span> <span class="comment">// As we regressed u an v such that they cannot further be lifted so</span></div>
<div class="line"><a id="l00192" name="l00192"></a><span class="lineno"> 192</span> <span class="comment">// that their ancestor would be different, the only logical</span></div>
<div class="line"><a id="l00193" name="l00193"></a><span class="lineno"> 193</span> <span class="comment">// consequence is that their parent is the sought answer.</span></div>
<div class="line"><a id="l00194" name="l00194"></a><span class="lineno"> 194</span> assert(<a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][0] == <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][0]);</div>
<div class="line"><a id="l00195" name="l00195"></a><span class="lineno"> 195</span> <span class="keywordflow">return</span> <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][0];</div>
<div class="line"><a id="l00196" name="l00196"></a><span class="lineno"> 196</span> }</div>
</div>
<div class="line"><a id="l00197" name="l00197"></a><span class="lineno"> 197</span> </div>
<div class="line"><a id="l00198" name="l00198"></a><span class="lineno"> 198</span> <span class="comment">/* \brief reference to the rooted tree this structure allows to query */</span></div>
<div class="line"><a id="l00199" name="l00199"></a><span class="lineno"> 199</span> <span class="keyword">const</span> <a class="code hl_class" href="../../d0/d58/classgraph_1_1_rooted_tree.html">RootedTree</a> &amp;tree;</div>
<div class="line"><a id="l00206" name="l00206"></a><span class="lineno"><a class="line" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad"> 206</a></span> std::vector&lt;std::vector&lt;int&gt; &gt; <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>;</div>
<div class="line"><a id="l00207" name="l00207"></a><span class="lineno"> 207</span> </div>
<div class="line"><a id="l00208" name="l00208"></a><span class="lineno"> 208</span> <span class="keyword">protected</span>:</div>
<div class="foldopen" id="foldopen00212" data-start="{" data-end="}">
<div class="line"><a id="l00212" name="l00212"></a><span class="lineno"><a class="line" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a42589cc39d6bbff6c997152f1b96e356"> 212</a></span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a42589cc39d6bbff6c997152f1b96e356">populate_up</a>() {</div>
<div class="line"><a id="l00213" name="l00213"></a><span class="lineno"> 213</span> <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>.resize(tree.<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>());</div>
<div class="line"><a id="l00214" name="l00214"></a><span class="lineno"> 214</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> vertex = 0; vertex &lt; tree.<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>(); ++vertex) {</div>
<div class="line"><a id="l00215" name="l00215"></a><span class="lineno"> 215</span> <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex].push_back(tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>[vertex]);</div>
<div class="line"><a id="l00216" name="l00216"></a><span class="lineno"> 216</span> }</div>
<div class="line"><a id="l00217" name="l00217"></a><span class="lineno"> 217</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> level = 0; (1 &lt;&lt; level) &lt; tree.<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>(); ++level) {</div>
<div class="line"><a id="l00218" name="l00218"></a><span class="lineno"> 218</span> <span class="keywordflow">for</span> (<span class="keywordtype">int</span> vertex = 0; vertex &lt; tree.<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>(); ++vertex) {</div>
<div class="line"><a id="l00219" name="l00219"></a><span class="lineno"> 219</span> <span class="comment">// up[vertex][level + 1] = 2^(level + 1) th ancestor of vertex =</span></div>
<div class="line"><a id="l00220" name="l00220"></a><span class="lineno"> 220</span> <span class="comment">// = 2^level th ancestor of 2^level th ancestor of vertex =</span></div>
<div class="line"><a id="l00221" name="l00221"></a><span class="lineno"> 221</span> <span class="comment">// = 2^level th ancestor of up[vertex][level]</span></div>
<div class="line"><a id="l00222" name="l00222"></a><span class="lineno"> 222</span> <a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex].push_back(<a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[<a class="code hl_variable" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex][level]][level]);</div>
<div class="line"><a id="l00223" name="l00223"></a><span class="lineno"> 223</span> }</div>
<div class="line"><a id="l00224" name="l00224"></a><span class="lineno"> 224</span> }</div>
<div class="line"><a id="l00225" name="l00225"></a><span class="lineno"> 225</span> }</div>
</div>
<div class="line"><a id="l00226" name="l00226"></a><span class="lineno"> 226</span>};</div>
</div>
<div class="line"><a id="l00227" name="l00227"></a><span class="lineno"> 227</span> </div>
<div class="line"><a id="l00228" name="l00228"></a><span class="lineno"> 228</span>} <span class="comment">// namespace graph</span></div>
<div class="line"><a id="l00229" name="l00229"></a><span class="lineno"> 229</span> </div>
<div class="foldopen" id="foldopen00234" data-start="{" data-end="}">
<div class="line"><a id="l00234" name="l00234"></a><span class="lineno"><a class="line" href="../../de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e"> 234</a></span><span class="keyword">static</span> <span class="keywordtype">void</span> <a class="code hl_function" href="../../de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>() {</div>
<div class="line"><a id="l00244" name="l00244"></a><span class="lineno"> 244</span> std::vector&lt;std::pair&lt;int, int&gt; &gt; edges = {</div>
<div class="line"><a id="l00245" name="l00245"></a><span class="lineno"> 245</span> {7, 1}, {1, 5}, {1, 3}, {3, 6}, {6, 2}, {2, 9}, {6, 8}, {4, 3}, {0, 4}};</div>
<div class="line"><a id="l00246" name="l00246"></a><span class="lineno"> 246</span> <a class="code hl_class" href="../../d0/d58/classgraph_1_1_rooted_tree.html">graph::RootedTree</a> t(edges, 3);</div>
<div class="line"><a id="l00247" name="l00247"></a><span class="lineno"> 247</span> <a class="code hl_class" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">graph::LowestCommonAncestor</a> lca(t);</div>
<div class="line"><a id="l00248" name="l00248"></a><span class="lineno"> 248</span> assert(lca.<a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">lowest_common_ancestor</a>(7, 4) == 3);</div>
<div class="line"><a id="l00249" name="l00249"></a><span class="lineno"> 249</span> assert(lca.<a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">lowest_common_ancestor</a>(9, 6) == 6);</div>
<div class="line"><a id="l00250" name="l00250"></a><span class="lineno"> 250</span> assert(lca.<a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">lowest_common_ancestor</a>(0, 0) == 0);</div>
<div class="line"><a id="l00251" name="l00251"></a><span class="lineno"> 251</span> assert(lca.<a class="code hl_function" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">lowest_common_ancestor</a>(8, 2) == 6);</div>
<div class="line"><a id="l00252" name="l00252"></a><span class="lineno"> 252</span>}</div>
</div>
<div class="line"><a id="l00253" name="l00253"></a><span class="lineno"> 253</span> </div>
<div class="foldopen" id="foldopen00255" data-start="{" data-end="}">
<div class="line"><a id="l00255" name="l00255"></a><span class="lineno"><a class="line" href="../../de/dde/lowest__common__ancestor_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4"> 255</a></span><span class="keywordtype">int</span> <a class="code hl_function" href="../../de/dde/lowest__common__ancestor_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a>() {</div>
<div class="line"><a id="l00256" name="l00256"></a><span class="lineno"> 256</span> <a class="code hl_function" href="../../de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a>();</div>
<div class="line"><a id="l00257" name="l00257"></a><span class="lineno"> 257</span> <span class="keywordflow">return</span> 0;</div>
<div class="line"><a id="l00258" name="l00258"></a><span class="lineno"> 258</span>}</div>
</div>
<div class="ttc" id="aclassgraph_1_1_graph_html"><div class="ttname"><a href="../../dc/d61/classgraph_1_1_graph.html">graph::Graph</a></div><div class="ttdef"><b>Definition</b> <a href="#l00053">lowest_common_ancestor.cpp:53</a></div></div>
<div class="ttc" id="aclassgraph_1_1_graph_html_a59940c462861f2fcf4951d1b6c084e6a"><div class="ttname"><a href="../../dc/d61/classgraph_1_1_graph.html#a59940c462861f2fcf4951d1b6c084e6a">graph::Graph::neighbors</a></div><div class="ttdeci">std::vector&lt; std::vector&lt; int &gt; &gt; neighbors</div><div class="ttdoc">for each vertex it stores a list indicies of its neighbors</div><div class="ttdef"><b>Definition</b> <a href="#l00077">lowest_common_ancestor.cpp:77</a></div></div>
<div class="ttc" id="aclassgraph_1_1_graph_html_a8839fa14bff19d2deab4a618447c13e5"><div class="ttname"><a href="../../dc/d61/classgraph_1_1_graph.html#a8839fa14bff19d2deab4a618447c13e5">graph::Graph::Graph</a></div><div class="ttdeci">Graph(size_t N, const std::vector&lt; std::pair&lt; int, int &gt; &gt; &amp;undirected_edges)</div><div class="ttdoc">Populate the adjacency list for each vertex in the graph. Assumes that evey edge is a pair of valid v...</div><div class="ttdef"><b>Definition</b> <a href="#l00062">lowest_common_ancestor.cpp:62</a></div></div>
<div class="ttc" id="aclassgraph_1_1_graph_html_a8930d1470d132b19e430d1c71f94c904"><div class="ttname"><a href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">graph::Graph::number_of_vertices</a></div><div class="ttdeci">int number_of_vertices() const</div><div class="ttdef"><b>Definition</b> <a href="#l00074">lowest_common_ancestor.cpp:74</a></div></div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">graph::LowestCommonAncestor</a></div><div class="ttdef"><b>Definition</b> <a href="#l00145">lowest_common_ancestor.cpp:145</a></div></div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html_a42589cc39d6bbff6c997152f1b96e356"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a42589cc39d6bbff6c997152f1b96e356">graph::LowestCommonAncestor::populate_up</a></div><div class="ttdeci">void populate_up()</div><div class="ttdef"><b>Definition</b> <a href="#l00212">lowest_common_ancestor.cpp:212</a></div></div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html_a46d10f669791e3da9a4809bd8ff8d3ad"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">graph::LowestCommonAncestor::up</a></div><div class="ttdeci">std::vector&lt; std::vector&lt; int &gt; &gt; up</div><div class="ttdoc">for every vertex stores a list of its ancestors by powers of two For each vertex, the first element o...</div><div class="ttdef"><b>Definition</b> <a href="#l00206">lowest_common_ancestor.cpp:206</a></div></div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html_a60151e19512b48cc0b14ea121df00488"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">graph::LowestCommonAncestor::lowest_common_ancestor</a></div><div class="ttdeci">int lowest_common_ancestor(int u, int v) const</div><div class="ttdoc">Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid i...</div><div class="ttdef"><b>Definition</b> <a href="#l00164">lowest_common_ancestor.cpp:164</a></div></div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html_a80825a4fd4c41860b689d253dd2c8e93"><div class="ttname"><a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a80825a4fd4c41860b689d253dd2c8e93">graph::LowestCommonAncestor::LowestCommonAncestor</a></div><div class="ttdeci">LowestCommonAncestor(const RootedTree &amp;tree_)</div><div class="ttdoc">Stores the tree and precomputs &quot;up lifts&quot;.</div><div class="ttdef"><b>Definition</b> <a href="#l00151">lowest_common_ancestor.cpp:151</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html">graph::RootedTree</a></div><div class="ttdef"><b>Definition</b> <a href="#l00084">lowest_common_ancestor.cpp:84</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html_a2ee3ad1161ac2532da30c3e22c265ad3"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">graph::RootedTree::level</a></div><div class="ttdeci">std::vector&lt; int &gt; level</div><div class="ttdoc">Stores the distance from the root.</div><div class="ttdef"><b>Definition</b> <a href="#l00106">lowest_common_ancestor.cpp:106</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html_a3831583a91914988897a4cc8748fda43"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">graph::RootedTree::parent</a></div><div class="ttdeci">std::vector&lt; int &gt; parent</div><div class="ttdoc">Stores parent of every vertex and for root its own index. The root is technically not its own parent,...</div><div class="ttdef"><b>Definition</b> <a href="#l00104">lowest_common_ancestor.cpp:104</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html_aacdeecac857623e9fbfe92590f3c504d"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html#aacdeecac857623e9fbfe92590f3c504d">graph::RootedTree::RootedTree</a></div><div class="ttdeci">RootedTree(const std::vector&lt; std::pair&lt; int, int &gt; &gt; &amp;undirected_edges, int root_)</div><div class="ttdoc">Constructs the tree by calculating parent for every vertex. Assumes a valid description of a tree is ...</div><div class="ttdef"><b>Definition</b> <a href="#l00093">lowest_common_ancestor.cpp:93</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html_ab22a97bf6209a085fc2d788c3c0dacbe"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html#ab22a97bf6209a085fc2d788c3c0dacbe">graph::RootedTree::root</a></div><div class="ttdeci">int root</div><div class="ttdoc">Index of the root vertex.</div><div class="ttdef"><b>Definition</b> <a href="#l00108">lowest_common_ancestor.cpp:108</a></div></div>
<div class="ttc" id="aclassgraph_1_1_rooted_tree_html_ae6928f3ebd491541e9570e746b877c1e"><div class="ttname"><a href="../../d0/d58/classgraph_1_1_rooted_tree.html#ae6928f3ebd491541e9570e746b877c1e">graph::RootedTree::populate_parents</a></div><div class="ttdeci">void populate_parents()</div><div class="ttdoc">Calculate the parents for all the vertices in the tree. Implements the breadth first search algorithm...</div><div class="ttdef"><b>Definition</b> <a href="#l00117">lowest_common_ancestor.cpp:117</a></div></div>
<div class="ttc" id="alowest__common__ancestor_8cpp_html_a483bb8ccf42aaf7375a83e91490eda1e"><div class="ttname"><a href="../../de/dde/lowest__common__ancestor_8cpp.html#a483bb8ccf42aaf7375a83e91490eda1e">tests</a></div><div class="ttdeci">static void tests()</div><div class="ttdef"><b>Definition</b> <a href="#l00234">lowest_common_ancestor.cpp:234</a></div></div>
<div class="ttc" id="alowest__common__ancestor_8cpp_html_ae66f6b31b5ad750f1fe042a706a4e3d4"><div class="ttname"><a href="../../de/dde/lowest__common__ancestor_8cpp.html#ae66f6b31b5ad750f1fe042a706a4e3d4">main</a></div><div class="ttdeci">int main()</div><div class="ttdef"><b>Definition</b> <a href="#l00255">lowest_common_ancestor.cpp:255</a></div></div>
<div class="ttc" id="anamespacegraph_html"><div class="ttname"><a href="../../df/dce/namespacegraph.html">graph</a></div><div class="ttdoc">Graph Algorithms.</div></div>
</div><!-- fragment --></div><!-- contents -->
</div><!-- doc-content -->
<!-- start footer part -->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
<li class="navelem"><a class="el" href="../../dir_12552d7fa429bf94a2e32e5cf39f7e69.html">graph</a></li><li class="navelem"><a class="el" href="../../de/dde/lowest__common__ancestor_8cpp.html">lowest_common_ancestor.cpp</a></li>
<li class="footer">Generated by <a href="https://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0 </li>
</ul>
</div>
</body>
</html>