Files
C-Plus-Plus/d9/d23/classgraph_1_1_lowest_common_ancestor.html
2020-08-27 14:33:59 +00:00

333 lines
28 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">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.19"/>
<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>
<link href="../../navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="../../resize.js"></script>
<script type="text/javascript" src="../../navtreedata.js"></script>
<script type="text/javascript" src="../../navtree.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 style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">Algorithms_in_C++
&#160;<span id="projectnumber">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.8.19 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "../../search",false,'Search');
/* @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:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('../../',true,false,'search.php','Search');
$(document).ready(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:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(document).ready(function(){initNavTree('d9/d23/classgraph_1_1_lowest_common_ancestor.html','../../'); initResizable(); });
/* @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">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</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="302" height="424"><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 name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a80825a4fd4c41860b689d253dd2c8e93"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#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". <a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a80825a4fd4c41860b689d253dd2c8e93">More...</a><br /></td></tr>
<tr class="separator:a80825a4fd4c41860b689d253dd2c8e93"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a60151e19512b48cc0b14ea121df00488"><td class="memItemLeft" align="right" valign="top">int&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#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. <a href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a60151e19512b48cc0b14ea121df00488">More...</a><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 name="pub-attribs"></a>
Public Attributes</h2></td></tr>
<tr class="memitem:ad6ae1f39c3ce27fc009970e6aa3c022a"><td class="memItemLeft" align="right" valign="top"><a id="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"><td class="memItemLeft" align="right" valign="top"><a id="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"><a class="el" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a></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 name="pro-methods"></a>
Protected Member Functions</h2></td></tr>
<tr class="memitem:a42589cc39d6bbff6c997152f1b96e356"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#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"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a80825a4fd4c41860b689d253dd2c8e93">&#9670;&nbsp;</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;&#160;</td>
<td class="paramname"><em>tree_</em></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"><a name="l00151"></a><span class="lineno"> 151</span>&#160; : tree(tree_) {</div>
<div class="line"><a name="l00152"></a><span class="lineno"> 152</span>&#160; <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a42589cc39d6bbff6c997152f1b96e356">populate_up</a>();</div>
<div class="line"><a name="l00153"></a><span class="lineno"> 153</span>&#160; }</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="416"><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"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a60151e19512b48cc0b14ea121df00488">&#9670;&nbsp;</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&#160;</td>
<td class="paramname"><em>u</em>, </td>
</tr>
<tr>
<td class="paramkey"></td>
<td></td>
<td class="paramtype">int&#160;</td>
<td class="paramname"><em>v</em>&#160;</td>
</tr>
<tr>
<td></td>
<td>)</td>
<td></td><td> 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"><a name="l00164"></a><span class="lineno"> 164</span>&#160; {</div>
<div class="line"><a name="l00165"></a><span class="lineno"> 165</span>&#160; <span class="comment">// Ensure u is the deeper (higher level) of the two vertices</span></div>
<div class="line"><a name="l00166"></a><span class="lineno"> 166</span>&#160; <span class="keywordflow">if</span> (tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[v] &gt; tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[u]) {</div>
<div class="line"><a name="l00167"></a><span class="lineno"> 167</span>&#160; <a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/algorithm/swap.html">std::swap</a>(u, v);</div>
<div class="line"><a name="l00168"></a><span class="lineno"> 168</span>&#160; }</div>
<div class="line"><a name="l00169"></a><span class="lineno"> 169</span>&#160; </div>
<div class="line"><a name="l00170"></a><span class="lineno"> 170</span>&#160; <span class="comment">// &quot;Lift&quot; u to the same level as v.</span></div>
<div class="line"><a name="l00171"></a><span class="lineno"> 171</span>&#160; <span class="keywordtype">int</span> level_diff = tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[u] - tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[v];</div>
<div class="line"><a name="l00172"></a><span class="lineno"> 172</span>&#160; <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 name="l00173"></a><span class="lineno"> 173</span>&#160; <span class="keywordflow">if</span> (level_diff &amp; (1 &lt;&lt; i)) {</div>
<div class="line"><a name="l00174"></a><span class="lineno"> 174</span>&#160; u = <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i];</div>
<div class="line"><a name="l00175"></a><span class="lineno"> 175</span>&#160; }</div>
<div class="line"><a name="l00176"></a><span class="lineno"> 176</span>&#160; }</div>
<div class="line"><a name="l00177"></a><span class="lineno"> 177</span>&#160; assert(tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[u] == tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a2ee3ad1161ac2532da30c3e22c265ad3">level</a>[v]);</div>
<div class="line"><a name="l00178"></a><span class="lineno"> 178</span>&#160; </div>
<div class="line"><a name="l00179"></a><span class="lineno"> 179</span>&#160; <span class="keywordflow">if</span> (u == v) {</div>
<div class="line"><a name="l00180"></a><span class="lineno"> 180</span>&#160; <span class="keywordflow">return</span> u;</div>
<div class="line"><a name="l00181"></a><span class="lineno"> 181</span>&#160; }</div>
<div class="line"><a name="l00182"></a><span class="lineno"> 182</span>&#160; </div>
<div class="line"><a name="l00183"></a><span class="lineno"> 183</span>&#160; <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 name="l00184"></a><span class="lineno"> 184</span>&#160; <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" 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 name="l00185"></a><span class="lineno"> 185</span>&#160; <span class="keywordflow">if</span> (<a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i] != <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][i]) {</div>
<div class="line"><a name="l00186"></a><span class="lineno"> 186</span>&#160; u = <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][i];</div>
<div class="line"><a name="l00187"></a><span class="lineno"> 187</span>&#160; v = <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][i];</div>
<div class="line"><a name="l00188"></a><span class="lineno"> 188</span>&#160; }</div>
<div class="line"><a name="l00189"></a><span class="lineno"> 189</span>&#160; }</div>
<div class="line"><a name="l00190"></a><span class="lineno"> 190</span>&#160; </div>
<div class="line"><a name="l00191"></a><span class="lineno"> 191</span>&#160; <span class="comment">// As we regressed u an v such that they cannot further be lifted so</span></div>
<div class="line"><a name="l00192"></a><span class="lineno"> 192</span>&#160; <span class="comment">// that their ancestor would be different, the only logical</span></div>
<div class="line"><a name="l00193"></a><span class="lineno"> 193</span>&#160; <span class="comment">// consequence is that their parent is the sought answer.</span></div>
<div class="line"><a name="l00194"></a><span class="lineno"> 194</span>&#160; assert(<a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][0] == <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[v][0]);</div>
<div class="line"><a name="l00195"></a><span class="lineno"> 195</span>&#160; <span class="keywordflow">return</span> <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[u][0];</div>
<div class="line"><a name="l00196"></a><span class="lineno"> 196</span>&#160; }</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="347" 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"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a42589cc39d6bbff6c997152f1b96e356">&#9670;&nbsp;</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"></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"><a name="l00212"></a><span class="lineno"> 212</span>&#160; {</div>
<div class="line"><a name="l00213"></a><span class="lineno"> 213</span>&#160; <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>.<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/resize.html">resize</a>(tree.<a class="code" href="../../dc/d61/classgraph_1_1_graph.html#ae2f6992450faa2c3da93edea0818869a">number_of_vertices</a>());</div>
<div class="line"><a name="l00214"></a><span class="lineno"> 214</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> vertex = 0; vertex &lt; tree.<a class="code" href="../../dc/d61/classgraph_1_1_graph.html#ae2f6992450faa2c3da93edea0818869a">number_of_vertices</a>(); ++vertex) {</div>
<div class="line"><a name="l00215"></a><span class="lineno"> 215</span>&#160; <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex].<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">push_back</a>(tree.<a class="code" href="../../d0/d58/classgraph_1_1_rooted_tree.html#a3831583a91914988897a4cc8748fda43">parent</a>[vertex]);</div>
<div class="line"><a name="l00216"></a><span class="lineno"> 216</span>&#160; }</div>
<div class="line"><a name="l00217"></a><span class="lineno"> 217</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> level = 0; (1 &lt;&lt; level) &lt; tree.<a class="code" href="../../dc/d61/classgraph_1_1_graph.html#ae2f6992450faa2c3da93edea0818869a">number_of_vertices</a>(); ++level) {</div>
<div class="line"><a name="l00218"></a><span class="lineno"> 218</span>&#160; <span class="keywordflow">for</span> (<span class="keywordtype">int</span> vertex = 0; vertex &lt; tree.<a class="code" href="../../dc/d61/classgraph_1_1_graph.html#ae2f6992450faa2c3da93edea0818869a">number_of_vertices</a>(); ++vertex) {</div>
<div class="line"><a name="l00219"></a><span class="lineno"> 219</span>&#160; <span class="comment">// up[vertex][level + 1] = 2^(level + 1) th ancestor of vertex =</span></div>
<div class="line"><a name="l00220"></a><span class="lineno"> 220</span>&#160; <span class="comment">// = 2^level th ancestor of 2^level th ancestor of vertex =</span></div>
<div class="line"><a name="l00221"></a><span class="lineno"> 221</span>&#160; <span class="comment">// = 2^level th ancestor of up[vertex][level]</span></div>
<div class="line"><a name="l00222"></a><span class="lineno"> 222</span>&#160; <a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex].<a class="codeRef" target="_blank" href="http://en.cppreference.com/w/cpp/container/vector/push_back.html">push_back</a>(<a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[<a class="code" href="../../d9/d23/classgraph_1_1_lowest_common_ancestor.html#a46d10f669791e3da9a4809bd8ff8d3ad">up</a>[vertex][level]][level]);</div>
<div class="line"><a name="l00223"></a><span class="lineno"> 223</span>&#160; }</div>
<div class="line"><a name="l00224"></a><span class="lineno"> 224</span>&#160; }</div>
<div class="line"><a name="l00225"></a><span class="lineno"> 225</span>&#160; }</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="587" height="155"><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 -->
<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 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="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> lowest_common_ancestor.cpp:212</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="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> lowest_common_ancestor.cpp:206</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="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 class="ttc" id="aclassgraph_1_1_graph_html_ae2f6992450faa2c3da93edea0818869a"><div class="ttname"><a href="../../dc/d61/classgraph_1_1_graph.html#ae2f6992450faa2c3da93edea0818869a">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>
<!-- 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="http://www.doxygen.org/index.html"><img class="footer" src="../../doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.8.19 </li>
</ul>
</div>
</body>
</html>