Files
C-Plus-Plus/d9/d23/classgraph_1_1_lowest_common_ancestor.html
2024-08-30 17:22:07 +00:00

334 lines
26 KiB
HTML

<!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>Algorithms_in_C++: graph::LowestCommonAncestor Class Reference</title>
<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="../../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/x-mathjax-config">
MathJax.Hub.Config({
extensions: ["tex2jax.js", "TeX/AMSmath.js", "TeX/AMSsymbols.js"],
jax: ["input/TeX","output/HTML-CSS"],
});
</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>
<link href="../../doxygen.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="projectalign">
<div id="projectname">Algorithms_in_C++<span id="projectnumber">&#160;1.0.0</span>
</div>
<div id="projectbrief">Set of 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('d9/d23/classgraph_1_1_lowest_common_ancestor.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="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="#pub-attribs">Public Attributes</a> &#124;
<a href="#pro-methods">Protected Member Functions</a> &#124;
<a href="../../da/d73/classgraph_1_1_lowest_common_ancestor-members.html">List of all members</a> </div>
<div class="headertitle"><div class="title">graph::LowestCommonAncestor Class Reference</div></div>
</div><!--header-->
<div class="contents">
<div class="dynheader">
Collaboration diagram for graph::LowestCommonAncestor:</div>
<div class="dyncontent">
<div class="center"><iframe scrolling="no" frameborder="0" src="../../d1/d71/classgraph_1_1_lowest_common_ancestor__coll__graph.svg" width="414" height="436"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
<center><span class="legend">[<a target="top" href="../../graph_legend.html">legend</a>]</span></center></div>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a80825a4fd4c41860b689d253dd2c8e93" id="r_a80825a4fd4c41860b689d253dd2c8e93"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a80825a4fd4c41860b689d253dd2c8e93">LowestCommonAncestor</a> (const <a class="el" href="../../d0/d58/classgraph_1_1_rooted_tree.html">RootedTree</a> &amp;tree_)</td></tr>
<tr class="memdesc:a80825a4fd4c41860b689d253dd2c8e93"><td class="mdescLeft">&#160;</td><td class="mdescRight">Stores the tree and precomputs "up lifts". <br /></td></tr>
<tr class="separator:a80825a4fd4c41860b689d253dd2c8e93"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a60151e19512b48cc0b14ea121df00488" id="r_a60151e19512b48cc0b14ea121df00488"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a60151e19512b48cc0b14ea121df00488">lowest_common_ancestor</a> (int u, int v) const</td></tr>
<tr class="memdesc:a60151e19512b48cc0b14ea121df00488"><td class="mdescLeft">&#160;</td><td class="mdescRight">Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid indices of vertices. Iterativelly modifies ("lifts") u an v until it finnds their lowest common ancestor. <br /></td></tr>
<tr class="separator:a60151e19512b48cc0b14ea121df00488"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-attribs" name="pub-attribs"></a>
Public Attributes</h2></td></tr>
<tr class="memitem:ad6ae1f39c3ce27fc009970e6aa3c022a" id="r_ad6ae1f39c3ce27fc009970e6aa3c022a"><td class="memItemLeft" align="right" valign="top"><a id="ad6ae1f39c3ce27fc009970e6aa3c022a" name="ad6ae1f39c3ce27fc009970e6aa3c022a"></a>
const <a class="el" href="../../d0/d58/classgraph_1_1_rooted_tree.html">RootedTree</a> &amp;&#160;</td><td class="memItemRight" valign="bottom"><b>tree</b></td></tr>
<tr class="separator:ad6ae1f39c3ce27fc009970e6aa3c022a"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a46d10f669791e3da9a4809bd8ff8d3ad" id="r_a46d10f669791e3da9a4809bd8ff8d3ad"><td class="memItemLeft" align="right" valign="top"><a id="a46d10f669791e3da9a4809bd8ff8d3ad" name="a46d10f669791e3da9a4809bd8ff8d3ad"></a>
<a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; <a class="elRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector.html">std::vector</a>&lt; int &gt; &gt;&#160;</td><td class="memItemRight" valign="bottom"><b>up</b></td></tr>
<tr class="memdesc:a46d10f669791e3da9a4809bd8ff8d3ad"><td class="mdescLeft">&#160;</td><td class="mdescRight">for every vertex stores a list of its ancestors by powers of two For each vertex, the first element of the corresponding list contains the index of its parent. The i-th element of the list is an index of the (2^i)-th ancestor of the vertex. <br /></td></tr>
<tr class="separator:a46d10f669791e3da9a4809bd8ff8d3ad"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table><table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pro-methods" name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:a42589cc39d6bbff6c997152f1b96e356" id="r_a42589cc39d6bbff6c997152f1b96e356"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a42589cc39d6bbff6c997152f1b96e356">populate_up</a> ()</td></tr>
<tr class="separator:a42589cc39d6bbff6c997152f1b96e356"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>A structure that holds a rooted tree and allow for effecient queries of the lowest common ancestor of two given vertices in the tree. </p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a80825a4fd4c41860b689d253dd2c8e93" name="a80825a4fd4c41860b689d253dd2c8e93"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a80825a4fd4c41860b689d253dd2c8e93">&#9670;&#160;</a></span>LowestCommonAncestor()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">graph::LowestCommonAncestor::LowestCommonAncestor </td>
<td>(</td>
<td class="paramtype">const <a class="el" href="../../d0/d58/classgraph_1_1_rooted_tree.html">RootedTree</a> &amp;</td> <td class="paramname"><span class="paramname"><em>tree_</em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">explicit</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Stores the tree and precomputs "up lifts". </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">tree_</td><td>rooted tree. </td></tr>
</table>
</dd>
</dl>
<div class="fragment"><div class="line"><span class="lineno"> 151</span> : tree(tree_) {</div>
<div class="line"><span class="lineno"> 152</span> <a class="code hl_function" href="#a42589cc39d6bbff6c997152f1b96e356">populate_up</a>();</div>
<div class="line"><span class="lineno"> 153</span> }</div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html_a42589cc39d6bbff6c997152f1b96e356"><div class="ttname"><a href="#a42589cc39d6bbff6c997152f1b96e356">graph::LowestCommonAncestor::populate_up</a></div><div class="ttdeci">void populate_up()</div><div class="ttdef"><b>Definition</b> lowest_common_ancestor.cpp:212</div></div>
</div><!-- fragment --><div class="dynheader">
Here is the call graph for this function:</div>
<div class="dyncontent">
<div class="center"><div class="zoom"><iframe scrolling="no" frameborder="0" src="../../d9/d23/classgraph_1_1_lowest_common_ancestor_a80825a4fd4c41860b689d253dd2c8e93_cgraph.svg" width="100%" height="413"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div></div>
</div>
</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="a60151e19512b48cc0b14ea121df00488" name="a60151e19512b48cc0b14ea121df00488"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a60151e19512b48cc0b14ea121df00488">&#9670;&#160;</a></span>lowest_common_ancestor()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">int graph::LowestCommonAncestor::lowest_common_ancestor </td>
<td>(</td>
<td class="paramtype">int</td> <td class="paramname"><span class="paramname"><em>u</em></span>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int</td> <td class="paramname"><span class="paramname"><em>v</em></span>&#160;) const</td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Query the structure to find the lowest common ancestor. Assumes that the provided numbers are valid indices of vertices. Iterativelly modifies ("lifts") u an v until it finnds their lowest common ancestor. </p>
<dl class="params"><dt>Parameters</dt><dd>
<table class="params">
<tr><td class="paramname">u</td><td>index of one of the queried vertex </td></tr>
<tr><td class="paramname">v</td><td>index of the other queried vertex </td></tr>
</table>
</dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>index of the vertex which is the lowet common ancestor of u and v </dd></dl>
<div class="fragment"><div class="line"><span class="lineno"> 164</span> {</div>
<div class="line"><span class="lineno"> 165</span> <span class="comment">// Ensure u is the deeper (higher level) of the two vertices</span></div>
<div class="line"><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"><span class="lineno"> 167</span> <a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/swap.html">std::swap</a>(u, v);</div>
<div class="line"><span class="lineno"> 168</span> }</div>
<div class="line"><span class="lineno"> 169</span> </div>
<div class="line"><span class="lineno"> 170</span> <span class="comment">// &quot;Lift&quot; u to the same level as v.</span></div>
<div class="line"><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"><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"><span class="lineno"> 173</span> <span class="keywordflow">if</span> (level_diff &amp; (1 &lt;&lt; i)) {</div>
<div class="line"><span class="lineno"> 174</span> u = <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i];</div>
<div class="line"><span class="lineno"> 175</span> }</div>
<div class="line"><span class="lineno"> 176</span> }</div>
<div class="line"><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"><span class="lineno"> 178</span> </div>
<div class="line"><span class="lineno"> 179</span> <span class="keywordflow">if</span> (u == v) {</div>
<div class="line"><span class="lineno"> 180</span> <span class="keywordflow">return</span> u;</div>
<div class="line"><span class="lineno"> 181</span> }</div>
<div class="line"><span class="lineno"> 182</span> </div>
<div class="line"><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"><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="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u].size()) - 1; i &gt;= 0; --i) {</div>
<div class="line"><span class="lineno"> 185</span> <span class="keywordflow">if</span> (<a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i] != <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][i]) {</div>
<div class="line"><span class="lineno"> 186</span> u = <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i];</div>
<div class="line"><span class="lineno"> 187</span> v = <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][i];</div>
<div class="line"><span class="lineno"> 188</span> }</div>
<div class="line"><span class="lineno"> 189</span> }</div>
<div class="line"><span class="lineno"> 190</span> </div>
<div class="line"><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"><span class="lineno"> 192</span> <span class="comment">// that their ancestor would be different, the only logical</span></div>
<div class="line"><span class="lineno"> 193</span> <span class="comment">// consequence is that their parent is the sought answer.</span></div>
<div class="line"><span class="lineno"> 194</span> assert(<a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][0] == <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][0]);</div>
<div class="line"><span class="lineno"> 195</span> <span class="keywordflow">return</span> <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][0];</div>
<div class="line"><span class="lineno"> 196</span> }</div>
<div class="ttc" id="aclassgraph_1_1_lowest_common_ancestor_html_a46d10f669791e3da9a4809bd8ff8d3ad"><div class="ttname"><a href="#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> lowest_common_ancestor.cpp:206</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> lowest_common_ancestor.cpp:106</div></div>
<div class="ttc" id="aswap_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/algorithm/swap.html">std::swap</a></div><div class="ttdeci">T swap(T... args)</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="../../d9/d23/classgraph_1_1_lowest_common_ancestor_a60151e19512b48cc0b14ea121df00488_cgraph.svg" width="346" 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>
</div>
<a id="a42589cc39d6bbff6c997152f1b96e356" name="a42589cc39d6bbff6c997152f1b96e356"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a42589cc39d6bbff6c997152f1b96e356">&#9670;&#160;</a></span>populate_up()</h2>
<div class="memitem">
<div class="memproto">
<table class="mlabels">
<tr>
<td class="mlabels-left">
<table class="memname">
<tr>
<td class="memname">void graph::LowestCommonAncestor::populate_up </td>
<td>(</td>
<td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
<td></td>
</tr>
</table>
</td>
<td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">protected</span></span> </td>
</tr>
</table>
</div><div class="memdoc">
<p>Populate the "up" structure. See above. </p>
<div class="fragment"><div class="line"><span class="lineno"> 212</span> {</div>
<div class="line"><span class="lineno"> 213</span> <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>.<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/resize.html">resize</a>(tree.<a class="code hl_function" href="../../dc/d61/classgraph_1_1_graph.html#a8930d1470d132b19e430d1c71f94c904">number_of_vertices</a>());</div>
<div class="line"><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"><span class="lineno"> 215</span> <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex].<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">push_back</a>(tree.<a class="code hl_variable" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>[vertex]);</div>
<div class="line"><span class="lineno"> 216</span> }</div>
<div class="line"><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"><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"><span class="lineno"> 219</span> <span class="comment">// up[vertex][level + 1] = 2^(level + 1) th ancestor of vertex =</span></div>
<div class="line"><span class="lineno"> 220</span> <span class="comment">// = 2^level th ancestor of 2^level th ancestor of vertex =</span></div>
<div class="line"><span class="lineno"> 221</span> <span class="comment">// = 2^level th ancestor of up[vertex][level]</span></div>
<div class="line"><span class="lineno"> 222</span> <a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex].<a class="code hl_functionRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">push_back</a>(<a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[<a class="code hl_variable" href="#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex][level]][level]);</div>
<div class="line"><span class="lineno"> 223</span> }</div>
<div class="line"><span class="lineno"> 224</span> }</div>
<div class="line"><span class="lineno"> 225</span> }</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> lowest_common_ancestor.cpp:74</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> lowest_common_ancestor.cpp:104</div></div>
<div class="ttc" id="apush_back_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">std::vector::push_back</a></div><div class="ttdeci">T push_back(T... args)</div></div>
<div class="ttc" id="aresize_html"><div class="ttname"><a href="http://en.cppreference.com/w/cpp/container/vector/resize.html">std::vector::resize</a></div><div class="ttdeci">T resize(T... args)</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="../../d9/d23/classgraph_1_1_lowest_common_ancestor_a42589cc39d6bbff6c997152f1b96e356_cgraph.svg" width="586" height="151"><p><b>This browser is not able to show SVG: try Firefox, Chrome, Safari, or Opera instead.</b></p></iframe></div>
</div>
</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>graph/<a class="el" href="../../de/dde/lowest__common__ancestor_8cpp.html">lowest_common_ancestor.cpp</a></li>
</ul>
</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="../../df/dce/namespacegraph.html">graph</a></li><li class="navelem"><a class="el" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html">LowestCommonAncestor</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>