{"id":91,"date":"2009-07-25T13:07:59","date_gmt":"2009-07-25T20:07:59","guid":{"rendered":"http:\/\/domemtech.com\/?p=91"},"modified":"2010-04-15T09:20:59","modified_gmt":"2010-04-15T16:20:59","slug":"computing-the-nearest-common-ancestor","status":"publish","type":"post","link":"http:\/\/165.227.223.229\/index.php\/2009\/07\/25\/computing-the-nearest-common-ancestor\/","title":{"rendered":"Computing the nearest common ancestor"},"content":{"rendered":"<p><strong> <\/strong><strong> <\/strong>This post is about computing the nearest common ancestor.\u00c2\u00a0 It is the result of a month or so of reading papers and implementation.\u00c2\u00a0 Although there has been a lot of research into the problem, there are no implementations online of the two main algorithms presented.\u00c2\u00a0 Worse, examples in the papers are practically useless.\u00c2\u00a0 For example, the Alstrup-Gavoille-Kaplan-Rauhe<strong> <\/strong>(AGKR)<strong> <\/strong>algorithm was first described in a technical report in August 2001, but it did not contain an example.\u00c2\u00a0 In 2002, it was presented at a conference but again it did not contain an example.\u00c2\u00a0 Finally, in  2004, it was published in a peer-reviewed journal and contained an example, albeit still incomplete.<br \/>\n<!--more--><\/p>\n<p><strong>Nearest common ancestor<\/strong><\/p>\n<p>Imagine meeting another person who has the same last name as you and suggests the possibility that you are related.\u00c2\u00a0 You and your acquaintance create your own family trees and ask whether you have any common ancestors.\u00c2\u00a0 If you are related, which relative is the most recent common ancestor?\u00c2\u00a0 This is the problem of the nearest common ancestor (NCA), which is also known as the least common ancestor, or lowest common ancestor, first presented by Aho <em>et al<\/em>. [1].<\/p>\n<p>The nearest common ancestor problem begins with a rooted general tree, <em>G<\/em> = (<em>V<\/em>, <em>E, r<\/em> \u00e2\u0088\u0088 <em>V<\/em>), and two nodes in the tree.\u00c2\u00a0 The set of ancestors of node is the set of nodes in the parent chain that starts at the node and ends at the root.\u00c2\u00a0 The set of ancestors <em>a<\/em>(<em>x<\/em>) of a node <em>x<\/em> \u00e2\u0088\u0088  <em>V<\/em> is<\/p>\n<p align=\"center\"><em>a<\/em>(<em>x<\/em>) = (<em>x<\/em> = <em>r<\/em>) ? {<em>x<\/em>} : {<em>x<\/em>} \u00e2\u0088\u00aa <em>a<\/em>(<em>Parent<\/em>(<em>x<\/em>))<\/p>\n<p>The proper ancestors of a node is the set of nodes in the parent chain that starts at the parent of the node and ends at the root, i.e., the set of ancestors for the node but not including the node itself.\u00c2\u00a0 The set of proper ancestors <em>p<\/em>(<em>x<\/em>) of a node <em>x<\/em> \u00e2\u0088\u0088<em>V<\/em> is<\/p>\n<p align=\"center\"><em>p<\/em>(<em>x<\/em>) = (<em>x<\/em> = <em>r<\/em>) ? \u00e2\u0088\u2026  : {<em>Parent<\/em>(<em>x<\/em>)} \u00e2\u0088\u00aa <em>p<\/em>(<em>Parent<\/em>(<em>x<\/em>))<\/p>\n<p>The set of common ancestors <em>ca<\/em>(<em>x<\/em>, <em>y<\/em>) of node <em>x, y<\/em> \u00e2\u0088\u0088<em>V<\/em> is<\/p>\n<p align=\"center\"><em>ca<\/em>(<em>x<\/em>, <em>y<\/em>) = <em>a<\/em>(<em>x<\/em>) \u00e2\u0088\u00a9 <em>a<\/em>(<em>y<\/em>)<\/p>\n<p>The nearest common ancestor <em>n<\/em><em>ca<\/em>(<em>x, y<\/em>)<em> =<\/em> <em>w<\/em> if <em>w<\/em> is a common ancestor of <em>x <\/em>and <em>y<\/em> with maximal depth <em>d<\/em>(<em>w<\/em>).\u00c2\u00a0 So, if <em>ca<\/em>(<em>x<\/em>, <em>y<\/em>) is the set of nodes <em>v<sub>1<\/sub><\/em>, <em>v<sub>2<\/sub><\/em>, <em>v<sub>3<\/sub><\/em>, \u00e2\u20ac\u00a6, <em>v<sub>k<\/sub><\/em>, then <em>v<sub>k<\/sub><\/em> is the least common ancestor if d(<em>v<sub>1<\/sub><\/em>) &lt; d(<em>v<sub>2<\/sub><\/em>) &lt; d(<em>v<sub>3<\/sub><\/em>) &lt; \u00e2\u20ac\u00a6 &lt; d(<em>v<sub>k<\/sub><\/em>).<\/p>\n<p align=\"center\"><em>nca<\/em>(<em>x<\/em>, <em>y<\/em>) = <em>v<sub>k<\/sub><\/em> where <em>v<sub>k<\/sub><\/em> \u00e2\u0088\u0088 <em>ca<\/em>(<em>x<\/em>, <em>y<\/em>) = { <em>v<sub>1<\/sub><\/em>, <em>v<sub>2<\/sub><\/em>, <em>v<sub>3<\/sub><\/em>, \u00e2\u20ac\u00a6, <em>v<sub>k<\/sub><\/em> } and <em>d<\/em>(<em>v<sub>n<\/sub><\/em>) &lt; <em>d<\/em>(<em>v<sub>k<\/sub><\/em>) for <em>n<\/em> \u00e2\u2030\u00a0 <em>k<\/em><\/p>\n<p>In Figure 1, the ancestors of <em>e<\/em> is the set {<em>a<\/em>, <em>b<\/em>, <em>e<\/em>}, and the ancestors of <em>m<\/em> is the set {<em>a<\/em>, <em>d<\/em>, <em>m<\/em>}.\u00c2\u00a0 The proper ancestors of <em>e<\/em> is the set {<em>a<\/em>, <em>b<\/em>}, and the proper ancestors of <em>m<\/em> is the set {<em>a<\/em>, <em>d<\/em>}.\u00c2\u00a0 The common ancestors of nodes <em>e<\/em> and <em>m<\/em> is {<em>a<\/em>}; the nearest common ancestor of nodes <em>e<\/em> and <em>m<\/em> is node <em>a<\/em>.<\/p>\n<p>The nearest common ancestor problem has many different applications: compiler construction [1], string search algorithms [2], and evolutionary trees [3].\u00c2\u00a0 It also has applications in graph drawing in the Walker algorithm [4] and planarity testing [5, 6], which we will discuss later on.<\/p>\n<p>Figure 1.\u00c2\u00a0 A rooted general tree with ancestors of two leafs.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-98\" title=\"nca-three-by-three\" src=\"http:\/\/domemtech.com\/wordpress\/wp-content\/uploads\/2009\/07\/nca-three-by-three-300x174.png\" alt=\"nca-three-by-three\" width=\"300\" height=\"174\" \/><\/p>\n<p><strong>Simple solution for the nearest common ancestor<\/strong><\/p>\n<p>The simplest solution to the nearest common ancestor problem is computed using two stacks.\u00c2\u00a0 In a loop, the ancestors for one node are pushed onto one stack.\u00c2\u00a0 In a second loop, the ancestors for the other node are pushed onto the other stack.\u00c2\u00a0 Finally, the top entries of each stack are popped and compared.\u00c2\u00a0 If the top entries are the same, then the ancestors are the same, and we note the ancestor in a temporary variable.\u00c2\u00a0 However, if the top entries differ, the nearest common ancestor has been found, and it is retained in the temporary variable.<\/p>\n<p>While this algorithm works fine for many applications, the issue can become probative in computational time when the nearest common ancestor is computed for many different node pairings. \u00c2\u00a0It computes the nearest common ancestor in <em>O<\/em>(n) time.<\/p>\n<p><span style=\"text-decoration: underline;\">Implementation in C#<\/span><\/p>\n<pre><code>\r\n1\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> Vertex NcaNaive<strong>(<\/strong>Vertex x<strong>,<\/strong> Vertex y<strong>)<\/strong>\r\n2\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n3\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Stack<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> s1 <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Stack<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n4\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Stack<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> s2 <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Stack<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n5\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex lca <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span>;<\/strong>\r\n6\r\n7\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">do<\/span><\/strong>\r\n8\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n9\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 s1<strong>.<\/strong>Push<strong>(<\/strong>x<strong>);<\/strong>\r\n10\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 x <strong>=<\/strong> x<strong>.<\/strong>Parent<strong>;<\/strong>\r\n\r\n11\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong> <strong><span style=\"text-decoration: underline;\">while<\/span><\/strong> <strong>(<\/strong>x <strong>!=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span>);<\/strong>\r\n12\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">do<\/span><\/strong>\r\n13\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n14\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 s2<strong>.<\/strong>Push<strong>(<\/strong>y<strong>);<\/strong>\r\n15\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 y <strong>=<\/strong> y<strong>.<\/strong>Parent<strong>;<\/strong>\r\n16\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong> <strong><span style=\"text-decoration: underline;\">while<\/span><\/strong> <strong>(<\/strong>y <strong>!=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span>);<\/strong>\r\n17\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">while<\/span><\/strong> <strong>(<\/strong>s1<strong>.<\/strong>Top<strong>()<\/strong> <strong>==<\/strong> s2<strong>.<\/strong>Top<strong>())<\/strong>\r\n18\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n19\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 lca <strong>=<\/strong> s1<strong>.<\/strong>Pop<strong>();<\/strong>\r\n20\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 s2<strong>.<\/strong>Pop<strong>();<\/strong>\r\n21\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n22\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> lca<strong>;<\/strong>\r\n23\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}\r\n<\/strong>\r\n<\/code><\/pre>\n<p>Each \u00e2\u20ac\u009cdo-while\u00e2\u20ac\u009d block (lines 7-11 and 12-16) computes a list of ancestors in order from a node to the root of the tree.\u00c2\u00a0 The \u00e2\u20ac\u009cwhile\u00e2\u20ac\u009d block at the end of the method (lines 17-21) compares each list of ancestors, processing each node from the root to the children until there is a difference in the ancestor list.\u00c2\u00a0 The last node that is equal is the nearest common ancestor, and is the temporary variable <em>lca<\/em>.<\/p>\n<p><strong>Schieber-Vishkin solution for the nearest common ancestor<\/strong><\/p>\n<p>The Schieber-Vishkin algorithm is probably the first solution for the nearest common ancestor that is considered efficient, simple, and understandable.\u00c2\u00a0 It is an extension of an earlier but more complicated solution by Harel and Tarjan [7].\u00c2\u00a0 It computes the nearest common ancestor in <em>O<\/em>(1) time after preprocessing the tree once in <em>O<\/em>(<em>n<\/em>) time.\u00c2\u00a0 Both of these solutions are based on the reduction of the tree into a <strong>complete binary tree<\/strong> that has been labeled with an inorder numbering, and is also known as a \u00e2\u20ac\u009csideways heap\u00e2\u20ac\u009d [8].\u00c2\u00a0 The complete binary tree has several interesting properties which we will now illustrate by example (see Figure 2).<\/p>\n<p>Figure 2.\u00c2\u00a0 A full binary tree of 31 nodes, inorder numbering.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-117\" title=\"Sideways-heap\" src=\"http:\/\/domemtech.com\/wordpress\/wp-content\/uploads\/2009\/07\/Sideways-heap-300x109.png\" alt=\"Sideways-heap\" width=\"300\" height=\"109\" \/><\/p>\n<p>The first property concerns the node inorder numbering and the depth of the node in the complete binary tree.\u00c2\u00a0 If the label of a particular node in represented as a binary integer, the level of the node in the tree can be determined by the position of the rightmost 1-bit in the label.\u00c2\u00a0 In Figure 2, node 19 has the binary representation 10011, and it is a leaf node because the rightmost 1-bit is in the 1\u00e2\u20ac\u2122s position.\u00c2\u00a0 Node 20 has the binary representation 10100, and it is two levels up from the leaves of the tree because the rightmost 1-bit is in the 4\u00e2\u20ac\u2122s position.\u00c2\u00a0 We define the <strong>height<\/strong> of a node relative to the leaves of the tree, <em>height(v)<\/em> as the following function:<\/p>\n<p align=\"center\"><em>height(v) <\/em>= \u00e2\u0152\u008a log<sub>2<\/sub>(<em>v<\/em> &amp; &#8211;<em>v<\/em>) \u00e2\u0152\u2039 <em> <\/em><\/p>\n<p>where &amp; is the bitwise-and binary operator, and \u00e2\u0152\u008a <em>x<\/em> \u00e2\u0152\u2039<em> <\/em>is the integer floor function.<\/p>\n<p>Using this formula, <em>height<\/em>(3) = \u00e2\u0152\u008a log<sub>2<\/sub>(00011 &amp; -00011) \u00e2\u0152\u2039<em> = <\/em>\u00e2\u0152\u008a log<sub>2<\/sub>(00011 &amp; -11101) \u00e2\u0152\u2039<em> = <\/em>\u00e2\u0152\u008a log<sub>2<\/sub>(00001) \u00e2\u0152\u2039 = 0 (i.e., it is a leaf node). \u00c2\u00a0The <em>height<\/em>(20) = \u00e2\u0152\u008a log<sub>2<\/sub>(10100 &amp; -10100) \u00e2\u0152\u2039<em> = <\/em>\u00e2\u0152\u008a log<sub>2<\/sub>(10100 &amp; -01100) \u00e2\u0152\u2039<em> = <\/em>\u00e2\u0152\u008a log<sub>2<\/sub>(00100) \u00e2\u0152\u2039 = 2 (i.e., two nodes up from a leaf node).<\/p>\n<p>A second property concerns the ancestor of a node and the difference in the height between the node and its ancestor.\u00c2\u00a0 Given a node <em>v<\/em> and the difference in the height <em>h<\/em>, the ancestor is<\/p>\n<p style=\"text-align: center;\"><em> a(v, h) <\/em>= ((<em>v &gt;&gt; h<\/em>) | 1) &lt;&lt; <em>h <\/em><\/p>\n<p>Several other examples: the ancestor of node 3 with height <em>h<\/em> = 4 is <em>a<\/em>(3,0) = ((3 &gt;&gt; 4) | 1) &lt;&lt; 4 = ((0) | 1) &lt;&lt; 4 = 1 &lt;&lt; 4 = 16; the ancestor of node 3 (00011) with height <em>h<\/em> = 1 is <em>a<\/em>(3,1) = ((3 &gt;&gt; 1) | 1) &lt;&lt; 1 = ((1) | 1) &lt;&lt; 1 = 1 &lt;&lt; 1 = 2; and, the ancestor of node 3 with height <em>h<\/em> = 0 is <em>a<\/em>(3,0) = ((3 &gt;&gt; 0) | 1) &lt;&lt; 0 = ((3) | 1) &lt;&lt; 0 = 3 &lt;&lt; 0 = 3.<\/p>\n<p>Because of these two properties, it is possible to compute the nearest common ancestor for two nodes in the complete binary tree for any two nodes <em>x<\/em> and <em>y<\/em> using the following formula:<\/p>\n<p>Let <em>h<\/em> = \u00e2\u0152\u008a log<sub>2<\/sub>(<em>x<\/em> &amp; &#8211;<em>y<\/em>) \u00e2\u0152\u2039 where the label for x is less than or equal to the label for <em>y<\/em>, then<\/p>\n<p align=\"center\"><em>NCA<sub>cbt<\/sub><\/em>(<em>x<\/em>, <em>y<\/em>) = ((<em>x<\/em> &gt;&gt; <em>h<\/em>) | 1) &lt;&lt; <em>h<\/em><\/p>\n<p>We now turn our attention back to the nearest common ancestor problem for a general tree.\u00c2\u00a0 Given a tree <em>T<\/em> = (<em>V<\/em>, <em>E<\/em>, <em>r<\/em> \u00e2\u0088\u0088<em>V<\/em>), the Schieber-Vishkin algorithm requires the following functions to be computed in a preprocessing step:<\/p>\n<p>1)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Preorder<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>Preorder<\/em>(<em>v<\/em>) maps nodes of the tree into integers that are the preorder numbers of the nodes in the tree.<\/p>\n<p>2)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Max<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>Max<\/em>(<em>v<\/em>) maps nodes of the tree into the maximum preorder number of a node in the subtree for <em>v<\/em>.<\/p>\n<p>3)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Inlabel<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>Inlabel<\/em>(<em>v<\/em>), known as the <strong>inlabel<\/strong> of a node, maps nodes of the tree into integer labels which correspond to the inorder numbers for nodes in the complete binary tree.\u00c2\u00a0 Function <em>Inlabel<\/em>(<em>v<\/em>) is defined as:<\/p>\n<p align=\"center\"><em>Inlabel<\/em>(<em>v<\/em>)<em> <\/em>= \u00e2\u0152\u008a log<sub>2<\/sub>(<em>Preorder<\/em>(<em>v<\/em>) &amp; &#8211;<em> Max<\/em>(<em>v<\/em>)) \u00e2\u0152\u2039<\/p>\n<p>4)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Ascendant<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>Ascendant<\/em>(<em>v<\/em>), known as the <strong>ascendant<\/strong> of a node, maps nodes of the tree into integers.\u00c2\u00a0 The ascendant is a bit map defined according to the following expression:<\/p>\n<p align=\"center\"><em>Ascendant<\/em>(<em>v<\/em>) = <em>Ascendant<\/em>(<em>Parent<\/em>(<em>v<\/em>))<em> | <\/em>(<em>Inlabel<\/em>(<em>v<\/em>)<em> <\/em>&amp;<em> -Inlabel<\/em>(<em>v<\/em>)), where <em>Ascendant<\/em>(<em>r<\/em>)<em> = 0<\/em><\/p>\n<p>The idea of the <em>Ascendant<\/em>(<em>v<\/em>) mapping is that it encodes the inlabel numbers of all ancestors of node <em>v. <\/em>A 1-bit in <em>Ascendant<\/em>(<em>v<\/em>) encodes the height of an ancestor of the node; a 0-bit indicates there is no ancestor at that level in the complete binary tree.<\/p>\n<p>5)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Head<\/em>:\u00c2\u00a0   \u00e2\u201e\u2022 \u00c2\u00a0\u00e2\u0086\u2019 V<\/p>\n<p>Function <em>Head<\/em>(<em>v<\/em>), known as the <strong>head <\/strong>of a node, maps an integer label that is the result of a simple calculation for the nearest common ancestor in the complete binary tree into a node in the general tree.\u00c2\u00a0 Function <em>Head<\/em>(<em>v<\/em>) is defined as:<\/p>\n<p align=\"center\"><em>Head<\/em>(<em>x<\/em>)<em> = v<\/em> such that <em>Inlabel<\/em>(<em>v<\/em>)<em> <\/em><em>\u00e2\u2030\u00a0<\/em><em> Inlabel<\/em>(<em>Parent<\/em>(<em>v<\/em>)) \u00e2\u0088\u00a9<em> Inlabel<\/em>(<em>v<\/em>)<em> = x<\/em><\/p>\n<p>Another way to understand this definition is that <em>Head<\/em>(<em>x<\/em>) is the node in the general tree that has the node that is an ancestor of <em>x<\/em> but has a different inlabel value as <em>x<\/em>.<\/p>\n<p>The <em>Inlabel<\/em>(<em>v<\/em>) relationship maps a node in the general tree to a node in the complete binary tree.\u00c2\u00a0 It is important to understand that the mapping <em>Inlabel<\/em>(<em>v<\/em>) is not a unique mapping, i.e., two nodes in the general tree can map to the same node in the complete binary tree.\u00c2\u00a0 In order to uniquely identify the nearest common ancestor of two nodes in the general tree, <em>Ascendant<\/em>(<em>v<\/em>)<em>,<\/em> and <em>Head<\/em>(<em>v<\/em>)<em> <\/em>are needed.\u00c2\u00a0 <em>Inlabel<\/em>(<em>v<\/em>) maintains two properties which are crucial for the algorithm to compute the nearest common ancestor.\u00c2\u00a0 First, <em>Inlabel<\/em>(<em>v<\/em>) partitions paths in the general tree, which are known as <strong>inlabel paths<\/strong>.\u00c2\u00a0 All of these paths partition the general tree into distinct paths.\u00c2\u00a0 This property is known as the <strong>path-partition property<\/strong>.\u00c2\u00a0 Second, a node <em>d<\/em> that is a descendant of node <em>p<\/em> in the general tree map to nodes <em>Inlabel<\/em>(<em>d<\/em>) and <em>Inlabel<\/em>(<em>p<\/em>) in the complete binary tree, respectively, such that <em>Inlabel<\/em>(<em>d<\/em>) is a descendant of (or the same as) <em>Inlabel<\/em>(<em>p<\/em>).\u00c2\u00a0 This is known as the <strong>descendance-preservation property<\/strong>.<\/p>\n<p>The preprocessing step can be done in two passes over the general tree in a depth-first search.\u00c2\u00a0 During the traversal, the values for <em>Preorder<\/em>(<em>v<\/em>)<em>,<\/em> <em>Max<\/em>(<em>v<\/em>)<em>, Inlabel<\/em>(<em>v<\/em>)<em>, and Head<\/em>(<em>v<\/em>) are computed.\u00c2\u00a0 <em>Preorder<\/em>(<em>v<\/em>) can be computed using a global variable for the node visited, incremented after associating the value with the node.\u00c2\u00a0 <em>Max<\/em>(<em>v<\/em>) is computed after traversing a node\u00e2\u20ac\u2122s entire subtree, associating the value of the global variable (minus 1 since it is post-incremented). \u00c2\u00a0After computing <em>Preorder<\/em>(<em>v<\/em>) and <em>Max<\/em>(<em>v<\/em>), <em>Inlabel<\/em>(<em>v<\/em>) can then be computed using its definition because all dependencies have been computed.\u00c2\u00a0 <em>Head<\/em>(<em>v<\/em>) can be computed in a couple different ways.\u00c2\u00a0 However, one method is to assign the node to an array indexed by the <em>Inlabel<\/em>(<em>v<\/em>) value.\u00c2\u00a0 As the depth-first search returns, the array entry is replaced with nodes in a particular inlabel path higher up in the general tree.\u00c2\u00a0 In the second pass, function <em>Ascendant<\/em>(<em>v<\/em>) can be computed, using information from the previous pass (using <em>Ascendant<\/em>(<em>Parent<\/em>(<em>v<\/em>)) and <em>Inlabel<\/em>(<em>v<\/em>)).<\/p>\n<p>The nearest common ancestor is computed in the following algorithm.<\/p>\n<pre><code>\r\n\r\n\/\/ Let <em>x<\/em> and <em>y<\/em> be the two nodes in the general tree.\r\n\/\/ Compute the height of the nearest common ancestor in the complete binary tree:\r\nlet <em>height(x,y) = <\/em> \u00e2\u0152\u008a log<sub>2<\/sub>(<em>Inlabel<\/em>(<em>x<\/em>)<em> <\/em>&amp;<em> -Inlabel<\/em>(<em>y<\/em>)) \u00e2\u0152\u2039\r\n\/\/ Note, if <em>Inlabel<\/em>(<em>x<\/em>) is greater than <em>Inlabel<\/em>(<em>y<\/em>), then reverse the assignments of <em>x<\/em> and <em>y<\/em>.\r\n\r\n\/\/ Compute the true height of the nearest common ancestor in the general tree:\r\nlet <em>k = Ascendant<\/em>(<em>x<\/em>) &amp; <em>Ascendant<\/em>(<em>y<\/em>) &amp; (1<em> <\/em>&lt;&lt;<em> height<\/em>(<em>x, y<\/em>)), and <em>trueheight<\/em>(<em>x, y<\/em>) =  \u00e2\u0152\u008a log<sub>2<\/sub>(<em>k<\/em> &amp; <em>-k<\/em>) \u00e2\u0152\u2039.\r\n\/\/ Compute two candidates for the nearest common ancestor.\r\nlet <em>j<\/em> = ((<em>Inlabel<\/em>(<em>x<\/em>)<em> <\/em>&gt;&gt;<em> trueheight<\/em>(<em>x, y<\/em>))<em> | <\/em>1)<em> <\/em>&lt;&lt;<em> trueheight<\/em>(<em>x, y<\/em>).\r\nif <em>j = Inlabel<\/em>(<em>x<\/em>) then let x\u00cb\u0086 = <em>x<\/em>\r\nelse\r\nlet <em>L<\/em> =<em> <\/em> \u00e2\u0152\u008a log<sub>2<\/sub>(<em>Ascendant<\/em>(<em>x<\/em>) &amp;<em> <\/em>((1 &lt;&lt;<em> trueheight<\/em>(<em>x, y<\/em>))<em> <\/em>-<em> <\/em>1) \u00e2\u0152\u008a\r\nx\u00cc\u201a = <em>Parent<\/em>(<em>Head<\/em>((<em>Inlabel<\/em>(<em>x<\/em>)<em> <\/em>&gt;&gt;<em> L) | <\/em>1<em>) <\/em>&lt;&lt;<em> L<\/em>))<em>\u00c2\u00a0<\/em>\r\nif <em>j = Inlabel <\/em>(<em>y<\/em>) then let   \u00c5\u00b7 \u00c2\u00a0= <em>y<\/em>\r\nelse\r\nlet <em>L<\/em> =<em> <\/em> \u00e2\u0152\u008a log<sub>2<\/sub>(<em>Ascendant<\/em>(<em>y<\/em>)<em> <\/em>&amp;<em> <\/em>((1 &lt;&lt;<em> trueheight<\/em>(<em>x, y<\/em>))<em> <\/em>-<em> <\/em>1) \u00e2\u0152\u2039\r\n\u00c5\u00b7 = <em>Parent<\/em>(<em>Head<\/em>((<em>Inlabel<\/em>(<em>y<\/em>)<em> &gt;&gt; L) | <\/em>1)<em> &lt;&lt; L<\/em>))<em>\u00c2\u00a0<\/em>\r\nlet <em>NCA<sub>SV<\/sub>(x,y) = z<\/em>, where <em>z<\/em> = xif Preorder( x\u00cc\u201a ) &lt; Preorder( \u00c5\u00b7 ), else  \u00c5\u00b7.\r\n\r\n<\/code><\/pre>\n<p>asd<\/p>\n<p><span style=\"text-decoration: underline;\">Implementation in C#<\/span><\/p>\n<p><span style=\"text-decoration: underline;\"><br \/>\n<\/span><\/p>\n<pre><code>\r\n1\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>;<\/strong>\r\n2\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>.<\/strong>Collections<strong>.<\/strong>Generic<strong>;<\/strong>\r\n3\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>.<\/strong>Text<strong>;<\/strong>\r\n4\r\n5\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">namespace<\/span><\/strong> GeneralTreeLayout\r\n6\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n7\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">class<\/span> NCA\r\n8\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n9\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Tree tree<strong>;<\/strong>\r\n10\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> Preorder<strong>;<\/strong>\r\n11\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> Inlabel<strong>;<\/strong>\r\n12\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> Ascendant<strong>;<\/strong>\r\n13\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>,<\/strong> Vertex<strong>&gt;<\/strong> Head<strong>;<\/strong>\r\n14\r\n15\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> NCA<strong>(<\/strong>Tree t<strong>)<\/strong>\r\n16\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n17\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree <strong>=<\/strong> t<strong>;<\/strong>\r\n18\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Preorder <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n19\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Inlabel <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n20\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Ascendant <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n21\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Head <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>,<\/strong> Vertex<strong>&gt;();<\/strong>\r\n22\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n23\r\n24\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> Preprocess<strong>()<\/strong>\r\n25\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n26\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>PreorderTraverse<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n27\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeAscendants<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>,<\/strong> 0<strong>);<\/strong>\r\n28\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n29\r\n30\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> number <strong>=<\/strong> 1<strong>;<\/strong>\r\n31\r\n32\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> PreorderTraverse<strong>(<\/strong>Vertex vertex<strong>)<\/strong>\r\n33\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n34\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> low <strong>=<\/strong> number<strong>;<\/strong>\r\n35\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Preorder<strong>.<\/strong>Add<strong>(<\/strong>vertex<strong>,<\/strong> number<strong>++);<\/strong>\r\n36\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge edge <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> vertex<strong>.<\/strong>Successors<strong>)<\/strong>\r\n37\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n38\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><strong>.<\/strong>PreorderTraverse<strong>(<\/strong>edge<strong>.<\/strong>To<strong>);<\/strong>\r\n39\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n40\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int high = number - 1;\r\n41\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int lh = (high &amp; -low);\r\n42\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int h = this.FloorLog2((uint)lh);\r\n43\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int inlabel = ((high &gt;&gt; h) | 1) &lt;&lt; h;\r\n44\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 this.Inlabel.Add(vertex, inlabel);\r\n45\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 if (!this.Head.ContainsKey(inlabel))\r\n46\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 this.Head.Add(inlabel, vertex);\r\n47\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 else\r\n48\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 this.Head[inlabel] = vertex;\r\n49\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n50\r\n51\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 void ComputeAscendants(Vertex vertex, int pascendant)\r\n52\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n53\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int inlabel = this.Inlabel[vertex];\r\n54\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int lsb = inlabel &amp; -inlabel;\r\n55\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int ascendant = pascendant | lsb;\r\n56\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 this.Ascendant.Add(vertex, ascendant);\r\n57\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0foreach (Edge edge in vertex.Successors)\r\n58\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n59\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 this.ComputeAscendants(edge.To, ascendant);\r\n60\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n61\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n62\r\n63\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 public Vertex ComputeNCA(Vertex x, Vertex y)\r\n64\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n65\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0int inlabelx = this.Inlabel[x];\r\n66\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int inlabely = this.Inlabel[y];\r\n67\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int xy = (inlabely &amp; -inlabelx);\r\n68\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int ch = FloorLog2((uint)xy);\r\n69\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int ancestor = ((inlabely &gt;&gt; ch) | 1) &lt;&lt; ch;\r\n70\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0int ax = this.Ascendant[x];\r\n71\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int ay = this.Ascendant[y];\r\n72\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int k = ax &amp; ay &amp; -(1 &lt;&lt; ch);\r\n73\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int th = FloorLog2((uint)(k &amp; -k));\r\n74\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int j = ((inlabelx &gt;&gt; th) | 1) &lt;&lt; th;\r\n75\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex xhat = null;\r\n76\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex yhat = null;\r\n77\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 if (j == inlabelx)\r\n78\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xhat = x;\r\n79\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 else\r\n80\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n81\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int l = this.FloorLog2((uint)( ax &amp; ((1 &lt;&lt; th) - 1)));\r\n82\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0int anc = ((inlabelx &gt;&gt; l) | 1) &lt;&lt; l;\r\n83\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xhat = this.Head[anc].Parent;\r\n84\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n85\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 if (j == inlabely)\r\n86\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 yhat = y;\r\n87\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 else\r\n88\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n89\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int l = this.FloorLog2((uint)( ay &amp; ((1 &lt;&lt; th) - 1)));\r\n90\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int anc = ((inlabely &gt;&gt; l) | 1) &lt;&lt; l;\r\n91\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 yhat = this.Head[anc].Parent;\r\n92\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n93\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex z = null;\r\n94\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 if (this.Preorder[xhat] &lt;= this.Preorder[yhat])\r\n95\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 z = xhat;\r\n96\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 else\r\n97\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 z = yhat;\r\n98\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 return z;\r\n99\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n100\r\n101\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 int FloorLog2(uint v)\r\n102\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n103\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 uint x = 0;\r\n104\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 while ((v = (v &gt;&gt; 1)) != 0)\r\n105\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 {\r\n106\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 x++;\r\n107\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n108\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 return (int)x;\r\n109\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n110\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 }\r\n111\u00c2\u00a0 }\r\n\r\n<\/strong><\/code><\/pre>\n<p><span style=\"text-decoration: underline;\">Example<\/span><\/p>\n<p>Figure 3.\u00c2\u00a0 Finding the nearest common ancestor using the Schieber-Vishkin algorithm.<\/p>\n<p>(a)<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-127\" title=\"LCA1\" src=\"http:\/\/domemtech.com\/wordpress\/wp-content\/uploads\/2009\/07\/LCA1-284x300.png\" alt=\"LCA1\" width=\"284\" height=\"300\" \/><\/p>\n<p>(b)<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-128\" title=\"LCA4\" src=\"http:\/\/domemtech.com\/wordpress\/wp-content\/uploads\/2009\/07\/LCA4-274x300.png\" alt=\"LCA4\" width=\"274\" height=\"300\" \/><\/p>\n<p>(c)<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-129\" title=\"LCA5\" src=\"http:\/\/domemtech.com\/wordpress\/wp-content\/uploads\/2009\/07\/LCA5-300x103.png\" alt=\"LCA5\" width=\"300\" height=\"103\" \/><\/p>\n<p>Consider the example tree displayed in Figure 3(a).\u00c2\u00a0 Compute the nearest common ancestor of node <em>F<\/em> and node <em>N<\/em>.<\/p>\n<p>First, label each node in the tree using a preorder numbering (line 26, and line 32 through 49).\u00c2\u00a0 These results are shown in Table 1.\u00c2\u00a0 For each node, the method <em>PreorderTraverse<\/em> also calculates the <em>Inlabel<\/em>(<em>v<\/em>) values.\u00c2\u00a0 The <em>Head<\/em>(<em>v<\/em>) mapping is also calculated.\u00c2\u00a0 These results are shown in Table 2.<\/p>\n<p>Table 1.\u00c2\u00a0 Shrieber-Vishkin computation for Figure 3<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"109\" valign=\"top\">Node v<\/td>\n<td width=\"108\" valign=\"top\">P(v)<\/td>\n<td width=\"112\" valign=\"top\">M(v)<\/td>\n<td width=\"112\" valign=\"top\">I(v)<\/td>\n<td width=\"103\" valign=\"top\">A(v)<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">A<\/td>\n<td width=\"108\" valign=\"top\">1<\/td>\n<td width=\"112\" valign=\"top\">18<\/td>\n<td width=\"112\" valign=\"top\">16<\/td>\n<td width=\"103\" valign=\"top\">16<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">B<\/td>\n<td width=\"108\" valign=\"top\">2<\/td>\n<td width=\"112\" valign=\"top\">18<\/td>\n<td width=\"112\" valign=\"top\">16<\/td>\n<td width=\"103\" valign=\"top\">16<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">C<\/td>\n<td width=\"108\" valign=\"top\">3<\/td>\n<td width=\"112\" valign=\"top\">6<\/td>\n<td width=\"112\" valign=\"top\">4<\/td>\n<td width=\"103\" valign=\"top\">20<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">D<\/td>\n<td width=\"108\" valign=\"top\">7<\/td>\n<td width=\"112\" valign=\"top\">12<\/td>\n<td width=\"112\" valign=\"top\">8<\/td>\n<td width=\"103\" valign=\"top\">24<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">E<\/td>\n<td width=\"108\" valign=\"top\">13<\/td>\n<td width=\"112\" valign=\"top\">18<\/td>\n<td width=\"112\" valign=\"top\">16<\/td>\n<td width=\"103\" valign=\"top\">16<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">F<\/td>\n<td width=\"108\" valign=\"top\">4<\/td>\n<td width=\"112\" valign=\"top\">4<\/td>\n<td width=\"112\" valign=\"top\">4<\/td>\n<td width=\"103\" valign=\"top\">20<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">G<\/td>\n<td width=\"108\" valign=\"top\">5<\/td>\n<td width=\"112\" valign=\"top\">5<\/td>\n<td width=\"112\" valign=\"top\">5<\/td>\n<td width=\"103\" valign=\"top\">21<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">H<\/td>\n<td width=\"108\" valign=\"top\">6<\/td>\n<td width=\"112\" valign=\"top\">6<\/td>\n<td width=\"112\" valign=\"top\">6<\/td>\n<td width=\"103\" valign=\"top\">22<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">I<\/td>\n<td width=\"108\" valign=\"top\">8<\/td>\n<td width=\"112\" valign=\"top\">11<\/td>\n<td width=\"112\" valign=\"top\">8<\/td>\n<td width=\"103\" valign=\"top\">24<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">J<\/td>\n<td width=\"108\" valign=\"top\">12<\/td>\n<td width=\"112\" valign=\"top\">12<\/td>\n<td width=\"112\" valign=\"top\">12<\/td>\n<td width=\"103\" valign=\"top\">28<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">K<\/td>\n<td width=\"108\" valign=\"top\">14<\/td>\n<td width=\"112\" valign=\"top\">17<\/td>\n<td width=\"112\" valign=\"top\">16<\/td>\n<td width=\"103\" valign=\"top\">16<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">L<\/td>\n<td width=\"108\" valign=\"top\">18<\/td>\n<td width=\"112\" valign=\"top\">18<\/td>\n<td width=\"112\" valign=\"top\">18<\/td>\n<td width=\"103\" valign=\"top\">18<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">M<\/td>\n<td width=\"108\" valign=\"top\">9<\/td>\n<td width=\"112\" valign=\"top\">9<\/td>\n<td width=\"112\" valign=\"top\">9<\/td>\n<td width=\"103\" valign=\"top\">25<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">N<\/td>\n<td width=\"108\" valign=\"top\">10<\/td>\n<td width=\"112\" valign=\"top\">10<\/td>\n<td width=\"112\" valign=\"top\">10<\/td>\n<td width=\"103\" valign=\"top\">26<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">O<\/td>\n<td width=\"108\" valign=\"top\">11<\/td>\n<td width=\"112\" valign=\"top\">11<\/td>\n<td width=\"112\" valign=\"top\">11<\/td>\n<td width=\"103\" valign=\"top\">25<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">P<\/td>\n<td width=\"108\" valign=\"top\">15<\/td>\n<td width=\"112\" valign=\"top\">15<\/td>\n<td width=\"112\" valign=\"top\">15<\/td>\n<td width=\"103\" valign=\"top\">17<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">Q<\/td>\n<td width=\"108\" valign=\"top\">16<\/td>\n<td width=\"112\" valign=\"top\">16<\/td>\n<td width=\"112\" valign=\"top\">16<\/td>\n<td width=\"103\" valign=\"top\">16<\/td>\n<\/tr>\n<tr>\n<td width=\"109\" valign=\"top\">R<\/td>\n<td width=\"108\" valign=\"top\">17<\/td>\n<td width=\"112\" valign=\"top\">17<\/td>\n<td width=\"112\" valign=\"top\">17<\/td>\n<td width=\"103\" valign=\"top\">17<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Table 2.\u00c2\u00a0 Shrieber-Vishkin head(x) for Figure 3<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td width=\"123\" valign=\"top\">Complete   binary tree node x<\/td>\n<td width=\"123\" valign=\"top\">H(x)<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">4<\/td>\n<td width=\"123\" valign=\"top\">C<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">5<\/td>\n<td width=\"123\" valign=\"top\">G<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">6<\/td>\n<td width=\"123\" valign=\"top\">H<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">9<\/td>\n<td width=\"123\" valign=\"top\">M<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">10<\/td>\n<td width=\"123\" valign=\"top\">N<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">11<\/td>\n<td width=\"123\" valign=\"top\">O<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">8<\/td>\n<td width=\"123\" valign=\"top\">D<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">12<\/td>\n<td width=\"123\" valign=\"top\">J<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">15<\/td>\n<td width=\"123\" valign=\"top\">P<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">16<\/td>\n<td width=\"123\" valign=\"top\">A<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">17<\/td>\n<td width=\"123\" valign=\"top\">R<\/td>\n<\/tr>\n<tr>\n<td width=\"123\" valign=\"top\">18<\/td>\n<td width=\"123\" valign=\"top\">L<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>This method uses the function <em>FloorLog2<\/em>(<em>v<\/em>), which calculates the expression \u00e2\u0152\u008a log<sub>2<\/sub>(<em>v<\/em>) \u00e2\u0152\u2039.\u00c2\u00a0 (Note, there are several other ways to compute the expression that are faster than the one show here).\u00c2\u00a0 Next, the Ascendant mapping is computed (line \u00c2\u00a027 and lines 51 through 61).<\/p>\n<p>The function <em>ComputeNCA<\/em> computes the nearest common ancestor (lines 63 through 99).\u00c2\u00a0 For nodes <em>F<\/em> and <em>N<\/em>, the height of the nearest common ancestor in the complete binary tree is <em>height(F, N) <\/em>=<em> <\/em>\u00e2\u0152\u008a log<sub>2<\/sub>(<em>Inlabel<\/em>(<em>F<\/em>) &amp; &#8211;<em>Inlabel<\/em>(<em>N<\/em>)) \u00e2\u0152\u2039 = 4.\u00c2\u00a0 The true height is first found via <em>k = Ascendant<\/em>(<em>F<\/em>) &amp; <em>Ascendant<\/em>(<em>N<\/em>) &amp; (1<em> <\/em>&lt;&lt; <em>height<\/em>(<em>F, \u00c2\u00a0N<\/em>)) = 20 &amp; 26 &amp; (1 &lt;&lt; 4) = 10100 &amp; 11010 &amp; 10000 = 10000 = 16.\u00c2\u00a0 Then <em>trueheight<\/em>(<em>F, N<\/em>) = \u00e2\u0152\u008a log<sub>2<\/sub>(16 &amp; -16) \u00e2\u0152\u2039 = 3.\u00c2\u00a0 Notice that the height in the general tree is different from the height in the complete binary tree.\u00c2\u00a0 Next, compute the candidates for the NCA.\u00c2\u00a0 Let <em>j <\/em>= ((<em>Inlabel<\/em>(<em>F<\/em>)<em> <\/em>&gt;&gt; <em>trueheight<\/em>(<em>F, N<\/em>))<em> | <\/em>1) &lt;&lt;<em> trueheight<\/em>(<em>F, N<\/em>)<em> = <\/em>((4 &gt;&gt; 3) | 1) &lt;&lt; 3 = 16. \u00c2\u00a0The results of computing                                                   \u00c2\u00a0and    \u00c2\u00a0both are node <em>B<\/em>.\u00c2\u00a0 So, <em>Nca<sub>SV<\/sub><\/em>(<em>F, N<\/em>)<em> <\/em>= <em>B<\/em>.<\/p>\n<p><strong>Alstrup-Gavoille-Kaplan-Rauhe solution for the nearest common ancestor<\/strong><\/p>\n<p>The Alstrup-Gavoille-Kaplan-Rauhe<strong> <\/strong>(AGKR)<strong> <\/strong>algorithm [9, 10] is another solution to the nearest common ancestor problem, and is similar to the Schieber-Vishkin algorithm.\u00c2\u00a0 After preprocessing the general tree in <em>O(n)<\/em> time, the solution can be computed in <em>O(1) <\/em>time.\u00c2\u00a0 The main difference between the AGKR algorithm and the Schieber-Vishkin algorithm is that the Schieber-Vishkin algorithm maps the general tree into a complete binary tree, whereas the AGKR algorithm does not. \u00c2\u00a0Instead, the AGKR algorithm is based on the computation of a common prefix between the labels of the two nodes in the general tree.<\/p>\n<p>The AGKR algorithm creates labels for each node in the general tree by partitioning the nodes and edges by classify each as either <em>light<\/em> or <em>heavy<\/em>, a scheme that was introduced by Harel and Tarjan [7].\u00c2\u00a0 A <strong>heavy<\/strong> <strong>node<\/strong> is a node has the greatest subtree size of all its siblings.\u00c2\u00a0 For each internal node <em>v<\/em>, we pick a child <em>w <\/em>of <em>v<\/em>, where size<em>(w) <\/em>= max{size<em>(<\/em><em>z<\/em><em>) <\/em>| <em>z <\/em>\u00e2\u0088\u0088children<em>(v)<\/em>} and classify <em>w <\/em>as <em>heavy<\/em>. \u00c2\u00a0All other nodes are <strong>light<\/strong> <strong>nodes<\/strong>.\u00c2\u00a0 All nodes that have no siblings are light nodes, and the root is defined to be a light node.\u00c2\u00a0 A <strong>heavy path<\/strong> is an edge from a node of any class to a node of heavy class.\u00c2\u00a0 All other paths are <strong>light paths<\/strong>.<\/p>\n<p>Given a tree <em>T<\/em> = (<em>V<\/em>, <em>E<\/em>, <em>r<\/em> \u00e2\u0088\u0088<em>V<\/em>), the AGKR algorithm defines the following functions:<\/p>\n<p>1)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Size<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>Size<\/em>(<em>v<\/em>) returns the size of the entire subtree of a node.<\/p>\n<p>2)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>IsHeavy<\/em>: <em>V<\/em> \u00e2\u0086\u2019 bool<\/p>\n<p>Function <em>IsHeavy<\/em>(<em>v<\/em>) partitions nodes of the general tree into heavy (denoted by true) or light (denoted by false):<\/p>\n<p><em>IsHeavy<\/em>(v) = true if\u00c2\u00a0 |<em>Children<\/em>(<em>Parent<\/em>(<em>v<\/em>))| &gt; 1 and [ \u00e2\u0088\u20ac <em>c<\/em> \u00e2\u0088\u0088<em>Children<\/em>(<em>Parent<\/em>(<em>v<\/em>)), where <em>c<\/em> <em>\u00e2\u2030\u00a0<\/em><em> <\/em><em>v<\/em> and <em>Size<\/em>(<em>c<\/em>) \u00e2\u2030\u00a4 <em>Size<\/em>(v)], else false.<\/p>\n<p>In other words, a node <em>v<\/em> is function heavy if there is exists a sibling of <em>v<\/em>, and all siblings of <em>v<\/em> have a subtree size less than the subtree size for <em>v<\/em>.<\/p>\n<p>3)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Apex<\/em>: <em>V<\/em> \u00e2\u0086\u2019 <em>V<\/em><\/p>\n<p>Function <em>Apex<\/em>(<em>v<\/em>) finds the <em>apex<\/em> of a node (see below).<\/p>\n<p>4)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>LightLabel<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>LightLabel<\/em>(<em>v<\/em>) returns the light label for a node.\u00c2\u00a0 The light label of a node is:<\/p>\n<p><em>LightLabel<\/em>(<em>v<\/em>)<em> = Size<\/em>(<em>v<\/em>)<\/p>\n<p>5)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>HeavyLabel<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>HeavyLabel<\/em>(<em>v<\/em>) returns the heavy label for a node. \u00c2\u00a0The heavy label of a node is:<\/p>\n<p><em>HeavyLabel<\/em>(<em>v<\/em>)<em> = Size<\/em>(<em>v<\/em>)<em> \u00e2\u20ac\u201c Size<\/em>(<em>h<\/em>)<em>, <\/em>where <em>h<\/em> \u00c3\u008e <em>Children<\/em>(<em>v<\/em>) and <em>IsHeavy<\/em>(<em>h<\/em>) = <em>true<\/em><\/p>\n<p>6)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>FullLabel<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>FullLabel<\/em>(<em>v<\/em>) maps nodes of the tree into integer labels.\u00c2\u00a0 Labels for the node are binary strings that are aligned to the leftmost (most significant) bit of an integer.\u00c2\u00a0 The integer labels are scaled to the appropriate size so that they fit into an appropriate integer unit on a machine (e.g., 32-bit unsigned integers).<\/p>\n<p>7)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Mask<\/em>: <em>V<\/em> \u00e2\u0086\u2019 \u00e2\u201e\u2022<\/p>\n<p>Function <em>Mask<\/em>(<em>v<\/em>) maps nodes of the tree into integer masks.\u00c2\u00a0 The mask is a binary string that corresponds to the label <em>FullLabel<\/em>(<em>v<\/em>) and notes portions of the label that are either light or heavy, explained below.<\/p>\n<p>8)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <em>Reverse<\/em>:\u00c2\u00a0 \u00e2\u201e\u2022    \u00e2\u0086\u2019 <em>V<\/em><\/p>\n<p>Function <em>Reverse<\/em>(<em>v<\/em>) maps an integer that is the result of a simple calculation for the nearest common ancestor into a node in the tree.\u00c2\u00a0 The mapping should always exist, since the two nodes in the nearest common ancestor problem are in the tree.<\/p>\n<p>In the preprocessing step, the AGKR algorithm first classifies nodes and edges of the tree as either <em>light<\/em> or <em>heavy<\/em>, a scheme that was introduced by Harel and Tarjan [7].\u00c2\u00a0 A <strong>heavy<\/strong> <strong>node<\/strong> is a node that must have at least one sibling and the node has the greatest subtree size of all its siblings. \u00c2\u00a0All other nodes are <strong>light<\/strong> <strong>nodes<\/strong>.\u00c2\u00a0 The nearest ancestor <em>a<\/em> of a node <em>v <\/em>in<em> <\/em>which node <em>a<\/em> is light and node v is heavy is known as an <strong>apex node<\/strong>. \u00c2\u00a0The sequence of heavy nodes from the apex node is known as a <strong>heavy path<\/strong>.\u00c2\u00a0 The heavy path starts at a light node, called the apex.\u00c2\u00a0 Using this partitioning, two types of labels are constructed for each node: a <em>heavy label<\/em>, and a <em>light label<\/em>.\u00c2\u00a0 The heavy and light labels are encoded in binary strings by considering the labels in a sequence:<\/p>\n<p>a)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 For heavy label encoding, the sequence is formed from the heavy labels for nodes in the heavy path.\u00c2\u00a0 For example, the heavy labels for the heavy path A-&gt;B-&gt;C are encoded by considering the labels in sequence: <em>HeavyLabel<\/em>(<em>A<\/em>), <em>HeavyLabel<\/em>(<em>B<\/em>), <em>HeavyLabel<\/em>(<em>C<\/em>).\u00c2\u00a0 There is only one encoding for each heavy label because the heavy node can belong only to one heavy path.\u00c2\u00a0 The encoding for heavy labels of light nodes is the empty string.<\/p>\n<p>b)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 For light label encoding, the sequence is formed from the light labels for sibling nodes that are light nodes.\u00c2\u00a0 For example, supposed the children of node <em>A<\/em> are <em>B<\/em>, <em>C<\/em>, and <em>D<\/em>.\u00c2\u00a0 Node <em>C<\/em> is a heavy node, and nodes <em>B<\/em> and <em>D<\/em> are light nodes.\u00c2\u00a0 The sequence for encoding the light labels is: <em>LightLabel<\/em>(<em>B<\/em>), <em>LightLabel<\/em>(<em>D<\/em>).\u00c2\u00a0 The encoding for light labels of heavy nodes is the empty string.<\/p>\n<p>The encoding is calculated as follows:<\/p>\n<p>1)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Create a sequence y<sub>i<\/sub>, I = 1 to k, from the integer values, either from the heavy labels, or the light children of a node. For example: heavy labels for heavy chain of nodes <em>A<\/em>-&gt;<em>B<\/em>-&gt;<em>D<\/em>-&gt;<em>I<\/em>-&gt;<em>M<\/em> are 1, 11, 2, 3, 1 (see Figure 4).<\/p>\n<p>2)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Compute s<em><sub>i<\/sub> <\/em>= \u00e2\u0088\u2018    <em>y<sub>j<\/sub><\/em>, j=1 .. i, and <em>i<\/em>=1 .. <em>k<\/em>-1, s<sub>0<\/sub> = 0.\u00c2\u00a0 From the example in the previous step, <em>s<sub>i<\/sub><\/em> = 0, 1, 12, 14, 17, 18.<\/p>\n<p>3)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Compute <em>f<sub>i<\/sub><\/em> = \u00e2\u0152\u008a log<sub>2<\/sub>(<em>y<sub>i<\/sub><\/em>) \u00e2\u0152\u2039, <em>i<\/em> = 1 .. <em>k<\/em>.\u00c2\u00a0 \u00c2\u00a0From the example in the previous steps, <em>f<sub>i<\/sub><\/em><sub> <\/sub>= 0, 1, 8, 2, 2, 1.<\/p>\n<p>4)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Compute <em>z<sub>i<\/sub><\/em>, <em>i<\/em> = 0 .. <em>k<\/em>:<\/p>\n<p><em>z<sub>i<\/sub><\/em> = (<em>s<sub>i<\/sub><\/em><sub>-1<\/sub> mod 2<em><sup>fi<\/sup><\/em> = 0) ? <em>s<sub>i<\/sub><\/em><sub>-1<\/sub> : <em>s<sub>i<\/sub><\/em><sub>-1<\/sub> \u00e2\u20ac\u201c (<em>s<sub>i<\/sub><\/em><sub>-1<\/sub> mod 2<em><sup>fi<\/sup><\/em>) + 2<em><sup>fi<\/sup><\/em><\/p>\n<p>From the example in the previous steps, <em>z<sub>i<\/sub><\/em> = 0, 0, 8, 12, 14, 17.<\/p>\n<p>5)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Compute <em>m<\/em> = max(<em>z<sub>i<\/sub><\/em>) for all <em>i<\/em> = 0 .. <em>k<\/em>.\u00c2\u00a0 From the example in the previous steps, <em>m<\/em> = 17.<\/p>\n<p>6)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Compute <em>w<\/em> = \u00e2\u0152\u008a log<sub>2<\/sub>(<em>m<\/em>) \u00e2\u0152\u2039 + 1.\u00c2\u00a0 From the example in the previous steps, <em>w<\/em> = 5.<\/p>\n<p>7)\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Compute encoding <em>e<sub>i<\/sub><\/em> = (<em>z<sub>i<\/sub><\/em> &gt;&gt; <em>f<sub>i<\/sub><\/em>) encoded with <em>w<\/em> \u00e2\u20ac\u201c <em>f<sub>i<\/sub><\/em> bits, <em>i<\/em> = 1 .. <em>k<\/em>.\u00c2\u00a0 From the example in the previous steps, the encodings for the labels in step 1 are 00000, 01, 0110, 0111, 10001.<\/p>\n<p>We define functions <em>EncodedHeavyLabel<\/em>(<em>v<\/em>) and <em>EncodedLightLabel<\/em>(<em>v<\/em>) as the encoded heavy and light labels for node <em>v<\/em>, respectively.<\/p>\n<p>Computing the NCA.<\/p>\n<p>Each label for a node uniquely identifies all of the edges from the root to the node.\u00c2\u00a0 The encodings constructed are a combination of the labels down a \u00e2\u20ac\u009cheavy\u00e2\u20ac\u009d path in the tree and across the \u00e2\u20ac\u009clight\u00e2\u20ac\u009d edges for siblings of a node. \u00c2\u00a0For any node, the encoding is defined as<\/p>\n<p><em>FullLabel<\/em>(<em>v<\/em>) = <em>FullLabel<\/em>(<em>Parent<\/em>(<em>Apex<\/em>(<em>v<\/em>)) \u00c2\u00b7 <em>Encode<\/em>d<em>LightLabel<\/em>(<em>Apex<\/em>(<em>v<\/em>)) \u00c2\u00b7 <em>Encode<\/em>d<em>HeavyLabel<\/em>(<em>v<\/em>)<\/p>\n<p>Given two nodes x and y that are in the tree the NCA is computed by computing the bitwise-AND between the two full labels and noting the location of the first difference from the left end of the labels.\u00c2\u00a0 The difference between the two labels can occur either within a light substring or within a heavy substring.<\/p>\n<p>If the difference occurs in the light label substrings<em>, <\/em>then let<em> <\/em><em>FullLabel<\/em>(<em>x<\/em>) = <em>L<sub>0 <\/sub>H<sub>0 <\/sub>L<sub>1 <\/sub>H<sub>1 <\/sub>L<sub>2 <\/sub>H<sub>2 <\/sub>\u00e2\u20ac\u00a6L<sub>i-1<\/sub> H<sub>i-1<\/sub> L<sub>i<\/sub><\/em> \u00e2\u20ac\u00a6 and <em>FullLabel<\/em>(<em>y<\/em>) = <em>L<sub>0 <\/sub>H<sub>0 <\/sub>L<sub>1 <\/sub>H<sub>1 <\/sub>L<sub>2 <\/sub>H<sub>2 <\/sub>\u00e2\u20ac\u00a6L<sub>i-1<\/sub> H<sub>i-1<\/sub> L\u00e2\u20ac\u2122<sub>i<\/sub><\/em> \u00e2\u20ac\u00a6, where <em>L<sub>i <\/sub><\/em>\u00c2\u00b9 <em>L\u00e2\u20ac\u2122<sub>I<\/sub><\/em>.\u00c2\u00a0 Then <em>FullLabel<\/em>(<em>NCA<\/em>(<em>x<\/em>, <em>y<\/em>)) = <em>L<sub>0 <\/sub>H<sub>0 <\/sub>L<sub>1 <\/sub>H<sub>1 <\/sub>L<sub>2 <\/sub>H<sub>2 <\/sub>\u00e2\u20ac\u00a6L<sub>i-1<\/sub> H<sub>i-1<\/sub><\/em>.<\/p>\n<p>If the difference occurs in the heavy label substrings, then let <em>FullLabel<\/em>(<em>x<\/em>) = <em>L<sub>0 <\/sub>H<sub>0 <\/sub>L<sub>1 <\/sub>H<sub>1 <\/sub>L<sub>2 <\/sub>H<sub>2 <\/sub>\u00e2\u20ac\u00a6L<sub>i-1<\/sub> H<sub>i-1<\/sub> L<sub>i<\/sub> H<sub>i<\/sub><\/em> \u00e2\u20ac\u00a6 and <em>FullLabel<\/em>(<em>y<\/em>) = <em>L<sub>0 <\/sub>H<sub>0 <\/sub>L<sub>1 <\/sub>H<sub>1 <\/sub>L<sub>2 <\/sub>H<sub>2 <\/sub>\u00e2\u20ac\u00a6L<sub>i-1<\/sub> H<sub>i-1<\/sub> L<sub>i<\/sub> H\u00e2\u20ac\u2122<sub>i<\/sub> <\/em>\u00e2\u20ac\u00a6, where <em>H<sub>i<\/sub><\/em><sub> <\/sub>\u00c2\u00b9 <em>H\u00e2\u20ac\u2122<sub>I<\/sub><\/em>.\u00c2\u00a0 Then <em>FullLabel<\/em>(<em>NCA<\/em>(<em>x<\/em>, <em>y<\/em>)) = <em>L<sub>0 <\/sub>H<sub>0 <\/sub>L<sub>1 <\/sub>H<sub>1 <\/sub>L<sub>2 <\/sub>H<sub>2 <\/sub>\u00e2\u20ac\u00a6L<sub>i-1<\/sub> H<sub>i-1<\/sub><\/em> min(<em>H<sub>1<\/sub><\/em>, <em>H\u00e2\u20ac\u2122<sub>1<\/sub><\/em>).\u00c2\u00a0 Note that the last substring of the label for the NCA is the minimum substring via alphabetic ordering.<\/p>\n<p><em>Mask<\/em>(<em>v<\/em>) is used to indicate which bits in the label are part of the heavy or light substrings.\u00c2\u00a0 The NCA is computed by the expression <em>Reverse<\/em>(<em>FullLabel<\/em>(<em>NCA<\/em>(<em>x<\/em>, <em>y<\/em>))).<\/p>\n<p>Implementation in C#<\/p>\n<pre><code>\r\n1\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>;<\/strong>\r\n2\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>.<\/strong>Collections<strong>.<\/strong>Generic<strong>;<\/strong>\r\n3\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>.<\/strong>Linq<strong>;<\/strong>\r\n4\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">using<\/span><\/strong> System<strong>.<\/strong>Text<strong>;<\/strong>\r\n5\r\n6\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">namespace<\/span><\/strong> GeneralTreeLayout\r\n7\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n8\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">class<\/span> Alstrup <strong>:<\/strong> NCA\r\n9\r\n10\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> Number<strong>;<\/strong>\r\n11\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> heavy<strong>;<\/strong>\r\n12\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> light<strong>;<\/strong>\r\n13\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> Vertex<strong>&gt;<\/strong> apex<strong>;<\/strong>\r\n14\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> UniqueApex<strong>;<\/strong>\r\n15\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> hlabel<strong>;<\/strong>\r\n16\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> llabel<strong>;<\/strong>\r\n17\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> String<strong>&gt;<\/strong> lightLabelEncodingString<strong>;<\/strong>\r\n18\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> String<strong>&gt;<\/strong> heavyLabelEncodingString<strong>;<\/strong>\r\n19\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> String<strong>&gt;<\/strong> labelEncodingString<strong>;<\/strong>\r\n20\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">uint<\/span><strong>&gt;<\/strong> labelEncodingBinary<strong>;<\/strong>\r\n21\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">uint<\/span><strong>&gt;<\/strong> kEncodingBinary<strong>;<\/strong>\r\n22\r\n23\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> Alstrup<strong>(<\/strong>Tree t<strong>)<\/strong>\r\n24\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>:<\/strong> <strong><span style=\"text-decoration: underline;\">base<\/span><\/strong><strong>(<\/strong>t<strong>)<\/strong>\r\n25\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n26\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Number <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n27\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavy <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n28\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>light <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n29\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>apex <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> Vertex<strong>&gt;();<\/strong>\r\n30\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>UniqueApex <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n31\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>hlabel <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n32\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>llabel <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n33\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>lightLabelEncodingString <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">string<\/span><strong>&gt;();<\/strong>\r\n34\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavyLabelEncodingString <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">string<\/span><strong>&gt;();<\/strong>\r\n35\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingString <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">string<\/span><strong>&gt;();<\/strong>\r\n36\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingBinary <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">uint<\/span><strong>&gt;();<\/strong>\r\n37\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>kEncodingBinary <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Dictionary<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">uint<\/span><strong>&gt;();<\/strong>\r\n38\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n39\r\n40\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">override<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> Preprocess<strong>()<\/strong>\r\n41\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n42\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeSize<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n43\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>light<strong>.<\/strong>Add<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n44\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Partition<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n45\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeApex<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>,<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n46\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Vertex v <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>UniqueApex<strong>)<\/strong>\r\n47\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n48\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeHeavyLabels<strong>(<\/strong>v<strong>);<\/strong>\r\n49\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n50\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeLightLabels<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n51\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Vertex v <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>UniqueApex<strong>)<\/strong>\r\n52\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n53\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>EncodeHeavyLabels<strong>(<\/strong>v<strong>);<\/strong>\r\n54\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n55\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>lightLabelEncodingString<strong>.<\/strong>Add<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>,<\/strong> \"\"<strong>);<\/strong>\r\n56\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>EncodeLightLabels<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n57\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeFullLabels<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>tree<strong>.<\/strong>Root<strong>);<\/strong>\r\n58\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n59\r\n60\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">int<\/span> ComputeSize<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n61\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n62\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Count the number of children in the whole subtree.\r\n63\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> sum <strong>=<\/strong> 1<strong>;<\/strong>\r\n64\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n65\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n66\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex c <strong>=<\/strong> e<strong>.<\/strong>To<strong>;<\/strong>\r\n67\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 sum <strong>+=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeSize<strong>(<\/strong>c<strong>);<\/strong>\r\n68\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n69\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Number<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> sum<strong>);<\/strong>\r\n70\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> sum<strong>;<\/strong>\r\n71\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n72\r\n73\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> ComputeBinaryLabels<strong>(<\/strong>Vertex v<strong>,<\/strong> String s<strong>)<\/strong>\r\n74\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n75\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Convert s into a binary and create a binary for h\/l substring\r\n76\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ boundaries.\r\n77\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> bin <strong>=<\/strong> 0<strong>;<\/strong>\r\n78\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> hl <strong>=<\/strong> 0<strong>;<\/strong>\r\n79\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> hlbin <strong>=<\/strong> 0<strong>;<\/strong>\r\n80\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> len <strong>=<\/strong> 0<strong>;<\/strong>\r\n81\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">int<\/span> i <strong>=<\/strong> 0<strong>;<\/strong> <strong>;<\/strong> <strong>++<\/strong>i<strong>)<\/strong>\r\n82\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n83\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>i <strong>==<\/strong> s<strong>.<\/strong>Length<strong>)<\/strong>\r\n84\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n85\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>s<strong>[<\/strong>i<strong>]<\/strong> <strong>==<\/strong> '1'<strong>)<\/strong>\r\n86\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n87\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 bin <strong>=<\/strong> bin <strong>&lt;&lt;<\/strong> 1<strong>;<\/strong>\r\n88\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 bin <strong>|=<\/strong> 1<strong>;<\/strong>\r\n89\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 len<strong>++;<\/strong>\r\n90\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hlbin <strong>=<\/strong> hlbin <strong>&lt;&lt;<\/strong> 1<strong>;<\/strong>\r\n91\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hlbin <strong>|=<\/strong> hl<strong>;<\/strong>\r\n92\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n93\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>s<strong>[<\/strong>i<strong>]<\/strong> <strong>==<\/strong> '0'<strong>)<\/strong>\r\n94\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n95\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 bin <strong>=<\/strong> bin <strong>&lt;&lt;<\/strong> 1<strong>;<\/strong>\r\n96\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 len<strong>++;<\/strong>\r\n97\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hlbin <strong>=<\/strong> hlbin <strong>&lt;&lt;<\/strong> 1<strong>;<\/strong>\r\n98\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hlbin <strong>|=<\/strong> hl<strong>;<\/strong>\r\n99\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n100\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>s<strong>[<\/strong>i<strong>]<\/strong> <strong>==<\/strong> 'L'<strong>)<\/strong>\r\n101\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n102\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hl <strong>=<\/strong> 0<strong>;<\/strong>\r\n103\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n104\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>s<strong>[<\/strong>i<strong>]<\/strong> <strong>==<\/strong> 'H'<strong>)<\/strong>\r\n105\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n106\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hl <strong>=<\/strong> 1<strong>;<\/strong>\r\n107\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n108\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n109\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Shift binaries all the way to the MSB, and\r\n110\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ set up hl to note end of label.\r\n111\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> diff <strong>=<\/strong> 32 <strong>-<\/strong> len<strong>;<\/strong>\r\n112\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hl <strong>=<\/strong> <strong>(<\/strong>hl <strong>==<\/strong> 0<strong>)<\/strong> <strong>?<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)<\/strong>1 <strong>:<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)<\/strong>0<strong>;<\/strong>\r\n113\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">int<\/span> i <strong>=<\/strong> 0<strong>;<\/strong> i <strong>&lt;<\/strong> diff<strong>;<\/strong> <strong>++<\/strong>i<strong>)<\/strong>\r\n114\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n115\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 bin <strong>=<\/strong> bin <strong>&lt;&lt;<\/strong> 1<strong>;<\/strong>\r\n116\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hlbin <strong>=<\/strong> hlbin <strong>&lt;&lt;<\/strong> 1<strong>;<\/strong>\r\n117\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hlbin <strong>|=<\/strong> hl<strong>;<\/strong>\r\n118\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n119\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingBinary<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> bin<strong>);<\/strong>\r\n120\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>kEncodingBinary<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> hlbin<strong>);<\/strong>\r\n121\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n122\r\n123\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> ComputeFullLabels<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n124\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n125\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Compute the labelEncodingString for a node v.\r\n126\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex ap <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>apex<strong>[<\/strong>v<strong>];<\/strong>\r\n127\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex parent <strong>=<\/strong> ap<strong>.<\/strong>Parent<strong>;<\/strong>\r\n128\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 String t <strong>=<\/strong> \"\"<strong>;<\/strong>\r\n129\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>parent <strong>!=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>)<\/strong>\r\n130\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n131\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingString<strong>.<\/strong>ContainsKey<strong>(<\/strong>parent<strong>))<\/strong>\r\n132\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 t <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingString<strong>[<\/strong>parent<strong>];<\/strong>\r\n133\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n134\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 String ll <strong>=<\/strong> \"\"<strong>;<\/strong>\r\n135\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>lightLabelEncodingString<strong>.<\/strong>ContainsKey<strong>(<\/strong>ap<strong>))<\/strong>\r\n136\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ll <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>lightLabelEncodingString<strong>[<\/strong>ap<strong>];<\/strong>\r\n137\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 String hl <strong>=<\/strong> \"\"<strong>;<\/strong>\r\n138\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavyLabelEncodingString<strong>.<\/strong>ContainsKey<strong>(<\/strong>v<strong>))<\/strong>\r\n139\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 hl <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavyLabelEncodingString<strong>[<\/strong>v<strong>];<\/strong>\r\n140\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 String total <strong>=<\/strong> t <strong>+<\/strong> \"L\" <strong>+<\/strong> ll <strong>+<\/strong> \"H\" <strong>+<\/strong> hl<strong>;<\/strong>\r\n141\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingString<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> total<strong>);<\/strong>\r\n142\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeBinaryLabels<strong>(<\/strong>v<strong>,<\/strong> total<strong>);<\/strong>\r\n143\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n144\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n145\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeFullLabels<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n146\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n147\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n148\r\n149\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> Partition<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n150\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n151\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Find child with max size.\r\n152\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> maxsize <strong>=<\/strong> 0<strong>;<\/strong>\r\n153\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex max <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>;<\/strong>\r\n154\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n155\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n156\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex to <strong>=<\/strong> e<strong>.<\/strong>To<strong>;<\/strong>\r\n157\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> value <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Number<strong>[<\/strong>to<strong>];<\/strong>\r\n158\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>value <strong>&gt;<\/strong> maxsize<strong>)<\/strong>\r\n159\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n160\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 maxsize <strong>=<\/strong> value<strong>;<\/strong>\r\n161\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 max <strong>=<\/strong> to<strong>;<\/strong>\r\n162\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n163\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n164\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>max <strong>!=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>)<\/strong>\r\n165\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n166\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavy<strong>.<\/strong>Add<strong>(<\/strong>max<strong>);<\/strong>\r\n167\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n168\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n169\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n170\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>e<strong>.<\/strong>To <strong>!=<\/strong> max<strong>)<\/strong>\r\n171\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n172\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>light<strong>.<\/strong>Add<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n173\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n174\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n175\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n176\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n177\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Partition<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n178\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n179\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n180\r\n181\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> ComputeApex<strong>(<\/strong>Vertex v<strong>,<\/strong> Vertex a<strong>)<\/strong>\r\n182\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n183\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>light<strong>.<\/strong>Contains<strong>(<\/strong>v<strong>))<\/strong>\r\n184\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n185\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ A light node is an apex by definition.\r\n186\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>UniqueApex<strong>.<\/strong>Add<strong>(<\/strong>v<strong>);<\/strong>\r\n187\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>apex<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> v<strong>);<\/strong>\r\n188\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 a <strong>=<\/strong> v<strong>;<\/strong>\r\n189\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n190\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong>\r\n191\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n192\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>apex<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> a<strong>);<\/strong>\r\n193\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n194\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n195\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n196\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex c <strong>=<\/strong> e<strong>.<\/strong>To<strong>;<\/strong>\r\n197\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeApex<strong>(<\/strong>c<strong>,<\/strong> a<strong>);<\/strong>\r\n198\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n199\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n200\r\n201\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> ComputeHeavyLabels<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n202\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n203\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> size <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Number<strong>[<\/strong>v<strong>];<\/strong>\r\n204\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> h <strong>=<\/strong> 0<strong>;<\/strong>\r\n205\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n206\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n207\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavy<strong>.<\/strong>Contains<strong>(<\/strong>e<strong>.<\/strong>To<strong>))<\/strong>\r\n208\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n209\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 h <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Number<strong>[<\/strong>e<strong>.<\/strong>To<strong>];<\/strong>\r\n210\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeHeavyLabels<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n211\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n212\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n213\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n214\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 size <strong>-=<\/strong> h<strong>;<\/strong>\r\n215\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>hlabel<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> size<strong>);<\/strong>\r\n216\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n217\r\n218\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> ComputeLightLabels<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n219\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n220\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>light<strong>.<\/strong>Contains<strong>(<\/strong>v<strong>))<\/strong>\r\n221\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>llabel<strong>.<\/strong>Add<strong>(<\/strong>v<strong>,<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>Number<strong>[<\/strong>v<strong>]);<\/strong>\r\n222\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n223\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n224\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>ComputeLightLabels<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n225\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n226\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n227\r\n228\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> EncodeHeavyLabels<strong>(<\/strong>Vertex a<strong>)<\/strong>\r\n229\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n230\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> hp <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>GetHP<strong>(<\/strong>a<strong>);<\/strong>\r\n231\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> hpHLabel <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>GetHeavyLabels<strong>(<\/strong>hp<strong>);<\/strong>\r\n232\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>String<strong>&gt;<\/strong> b <strong>=<\/strong> IntegerAlphabeticEncoding<strong>.<\/strong>Encoding<strong>(<\/strong>hpHLabel<strong>);<\/strong>\r\n233\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">int<\/span> i <strong>=<\/strong> 0<strong>;<\/strong> i <strong>&lt;<\/strong> hp<strong>.<\/strong>Count<strong>;<\/strong> <strong>++<\/strong>i<strong>)<\/strong>\r\n234\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n235\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavyLabelEncodingString<strong>.<\/strong>Add<strong>(<\/strong>hp<strong>[<\/strong>i<strong>],<\/strong> b<strong>[<\/strong>i<strong>]);<\/strong>\r\n236\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n237\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n238\r\n239\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> GetHP<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n240\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n241\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(!<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>UniqueApex<strong>.<\/strong>Contains<strong>(<\/strong>v<strong>))<\/strong>\r\n242\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">throw<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> Exception<strong>(<\/strong>\"Not an apex.\"<strong>);<\/strong>\r\n243\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> list <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n244\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0list<strong>.<\/strong>Add<strong>(<\/strong>v<strong>);<\/strong>\r\n245\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex next <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>;<\/strong>\r\n246\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">do<\/span><\/strong>\r\n247\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n248\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 next <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>;<\/strong>\r\n249\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n250\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n251\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>heavy<strong>.<\/strong>Contains<strong>(<\/strong>e<strong>.<\/strong>To<strong>))<\/strong>\r\n252\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n253\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 next <strong>=<\/strong> e<strong>.<\/strong>To<strong>;<\/strong>\r\n254\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 list<strong>.<\/strong>Add<strong>(<\/strong>next<strong>);<\/strong>\r\n255\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n256\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n257\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n258\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 v <strong>=<\/strong> next<strong>;<\/strong>\r\n259\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong> <strong><span style=\"text-decoration: underline;\">while<\/span><\/strong> <strong>(<\/strong>next <strong>!=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>);<\/strong>\r\n260\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> list<strong>;<\/strong>\r\n261\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n262\r\n263\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> GetHeavyLabels<strong>(<\/strong>List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> list<strong>)<\/strong>\r\n264\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n265\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Convert a list of vertices into a list of heavy labels.\r\n266\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> newlist <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n267\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Vertex v <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> list<strong>)<\/strong>\r\n268\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n269\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 newlist<strong>.<\/strong>Add<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>hlabel<strong>[<\/strong>v<strong>]);<\/strong>\r\n270\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n271\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> newlist<strong>;<\/strong>\r\n272\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n273\r\n274\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> EncodeLightLabels<strong>(<\/strong>Vertex v<strong>)<\/strong>\r\n275\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n276\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> lightvertices <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong>Vertex<strong>&gt;();<\/strong>\r\n277\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n278\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n279\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>light<strong>.<\/strong>Contains<strong>(<\/strong>e<strong>.<\/strong>To<strong>))<\/strong>\r\n280\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n281\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 lightvertices<strong>.<\/strong>Add<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n282\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n283\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n284\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> lightlabels <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>GetLightLabels<strong>(<\/strong>lightvertices<strong>);<\/strong>\r\n285\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong>String<strong>&gt;<\/strong> labels <strong>=<\/strong> IntegerAlphabeticEncoding<strong>.<\/strong>Encoding<strong>(<\/strong>lightlabels<strong>);<\/strong>\r\n286\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>AssociateLLabels<strong>(<\/strong>lightvertices<strong>,<\/strong> labels<strong>);<\/strong>\r\n287\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Edge e <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> v<strong>.<\/strong>Successors<strong>)<\/strong>\r\n288\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n289\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>EncodeLightLabels<strong>(<\/strong>e<strong>.<\/strong>To<strong>);<\/strong>\r\n290\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n291\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n292\r\n293\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> GetLightLabels<strong>(<\/strong>List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> list<strong>)<\/strong>\r\n294\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n295\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\/\/ Convert a list of vertices into a list of light labels.\r\n296\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;<\/strong> newlist <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">new<\/span><\/strong> List<strong>&lt;<\/strong><span style=\"text-decoration: underline;\">int<\/span><strong>&gt;();<\/strong>\r\n297\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>Vertex v <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> list<strong>)<\/strong>\r\n298\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n299\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 newlist<strong>.<\/strong>Add<strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>llabel<strong>[<\/strong>v<strong>]);<\/strong>\r\n300\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n301\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> newlist<strong>;<\/strong>\r\n302\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n303\r\n304\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">private<\/span><\/strong> <span style=\"text-decoration: underline;\">void<\/span> AssociateLLabels<strong>(<\/strong>List<strong>&lt;<\/strong>Vertex<strong>&gt;<\/strong> vertices<strong>,<\/strong> List<strong>&lt;<\/strong>String<strong>&gt;<\/strong> labels<strong>)<\/strong>\r\n305\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n306\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">int<\/span> i <strong>=<\/strong> 0<strong>;<\/strong> i <strong>&lt;<\/strong> vertices<strong>.<\/strong>Count<strong>;<\/strong> <strong>++<\/strong>i<strong>)<\/strong>\r\n307\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n308\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>lightLabelEncodingString<strong>.<\/strong>Add<strong>(<\/strong>vertices<strong>[<\/strong>i<strong>],<\/strong> labels<strong>[<\/strong>i<strong>]);<\/strong>\r\n309\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n310\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n311\r\n312\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">override<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">public<\/span><\/strong> Vertex ComputeNCA<strong>(<\/strong>Vertex x<strong>,<\/strong> Vertex y<strong>)<\/strong>\r\n313\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n314\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ NCA label to be found.\r\n315\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> ncalabel <strong>=<\/strong> 0<strong>;<\/strong>\r\n316\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> ncak <strong>=<\/strong> 0<strong>;<\/strong>\r\n317\r\n318\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Get labels for each vertex.\r\n319\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> xs <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingBinary<strong>[<\/strong>x<strong>];<\/strong>\r\n320\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> ys <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingBinary<strong>[<\/strong>y<strong>];<\/strong>\r\n321\r\n322\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Get heavy\/light masks for each vertex.\r\n323\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ These are needed to know whether the first difference\r\n324\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ in the labels is on a heavy label substring, or a light\r\n325\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ label substring.\r\n326\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> xk <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>kEncodingBinary<strong>[<\/strong>x<strong>];<\/strong>\r\n327\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> yk <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>kEncodingBinary<strong>[<\/strong>y<strong>];<\/strong>\r\n328\r\n329\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Compute the common prefix and the location\r\n330\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ of the first difference from the left.\r\n331\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> h <strong>=<\/strong> Bithacks<strong>.<\/strong>FloorLog2<strong>(<\/strong>xs <strong>^<\/strong> ys<strong>);<\/strong>\r\n332\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> hk <strong>=<\/strong> Bithacks<strong>.<\/strong>FloorLog2<strong>(<\/strong>xk <strong>^<\/strong> yk<strong>);<\/strong>\r\n333\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>h <strong>==<\/strong> 0<strong>)<\/strong>\r\n334\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 h <strong>=<\/strong> hk<strong>;<\/strong>\r\n335\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>h <strong>==<\/strong> 0<strong>)<\/strong>\r\n336\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> x<strong>;<\/strong>\r\n337\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> v <strong>=<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)(<\/strong>1 <strong>&lt;&lt;<\/strong> h<strong>);<\/strong>\r\n338\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> commonprefix <strong>=<\/strong> <strong>(<\/strong>xs <strong>&gt;&gt;<\/strong> h<strong>)<\/strong> <strong>&lt;&lt;<\/strong> h<strong>;<\/strong>\r\n339\r\n340\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Compute if the bit that is different is heavy or light\r\n341\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ in either of the two labels.\r\n342\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ ... or both!\r\n343\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">bool<\/span> xheavy <strong>=<\/strong> <strong>(<\/strong>xk <strong>&amp;<\/strong> v<strong>)<\/strong> <strong>!=<\/strong> 0<strong>;<\/strong>\r\n344\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">bool<\/span> yheavy <strong>=<\/strong> <strong>(<\/strong>yk <strong>&amp;<\/strong> v<strong>)<\/strong> <strong>!=<\/strong> 0<strong>;<\/strong>\r\n345\r\n346\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Count number of heavy\/light changes in each label.\r\n347\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ We need to know the first actual difference.\r\n348\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> xcount <strong>=<\/strong> 0<strong>;<\/strong>\r\n349\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n350\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> i <strong>=<\/strong> 31<strong>;<\/strong>\r\n351\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(;<\/strong> i <strong>&gt;=<\/strong> h<strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n352\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n353\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">bool<\/span> hv <strong>=<\/strong> <strong>(<\/strong>xk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>!=<\/strong> 0<strong>;<\/strong>\r\n354\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>hv<strong>)<\/strong>\r\n355\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n356\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xcount<strong>++;<\/strong>\r\n357\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(;<\/strong> i <strong>&gt;=<\/strong> h<strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n358\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>((<\/strong>xk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>==<\/strong> 0<strong>)<\/strong>\r\n359\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n360\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xcount<strong>++;<\/strong>\r\n361\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n362\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n363\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n364\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong>\r\n365\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n366\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0xcount<strong>++;<\/strong>\r\n367\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(;<\/strong> i <strong>&gt;=<\/strong> h<strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n368\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>((<\/strong>xk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>!=<\/strong> 0<strong>)<\/strong>\r\n369\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n370\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xcount<strong>++;<\/strong>\r\n371\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n372\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n373\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n374\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n375\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n376\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> ycount <strong>=<\/strong> 0<strong>;<\/strong>\r\n377\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n378\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> i <strong>=<\/strong> 31<strong>;<\/strong>\r\n379\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(;<\/strong> i <strong>&gt;=<\/strong> h<strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n380\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n381\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">bool<\/span> hv <strong>=<\/strong> <strong>(<\/strong>yk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>!=<\/strong> 0<strong>;<\/strong>\r\n382\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>hv<strong>)<\/strong>\r\n383\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n384\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ycount<strong>++;<\/strong>\r\n385\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(;<\/strong> i <strong>&gt;=<\/strong> h<strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n386\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>((<\/strong>yk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>==<\/strong> 0<strong>)<\/strong>\r\n387\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n388\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ycount<strong>++;<\/strong>\r\n389\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n390\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n391\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n392\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong>\r\n393\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n394\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0ycount<strong>++;<\/strong>\r\n395\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(;<\/strong> i <strong>&gt;=<\/strong> h<strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n396\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>((<\/strong>yk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>!=<\/strong> 0<strong>)<\/strong>\r\n397\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n398\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ycount<strong>++;<\/strong>\r\n399\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n400\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0<strong>}<\/strong>\r\n401\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n402\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n403\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n404\r\n405\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Determine which is different, the L bits or the H bits.\r\n406\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> j<strong>;<\/strong>\r\n407\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">bool<\/span> xboundary<strong>,<\/strong> yboundary<strong>;<\/strong>\r\n408\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong>j <strong>=<\/strong> h <strong>+<\/strong> 1<strong>;<\/strong> j <strong>&lt;=<\/strong> 31<strong>;<\/strong> j<strong>++)<\/strong>\r\n409\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n410\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Are we on a boundary between the heavy\/light labels?\r\n411\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> vm1 <strong>=<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)(<\/strong>1 <strong>&lt;&lt;<\/strong> j<strong>);<\/strong>\r\n412\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xboundary <strong>=<\/strong> <strong>((<\/strong>xk <strong>&amp;<\/strong> vm1<strong>)<\/strong> <strong>!=<\/strong> 0 <strong>?<\/strong> <strong>!<\/strong>xheavy <strong>:<\/strong> xheavy<strong>);<\/strong>\r\n413\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 yboundary <strong>=<\/strong> <strong>((<\/strong>yk <strong>&amp;<\/strong> vm1<strong>)<\/strong> <strong>!=<\/strong> 0 <strong>?<\/strong> <strong>!<\/strong>yheavy <strong>:<\/strong> yheavy<strong>);<\/strong>\r\n414\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>xboundary <strong>||<\/strong> yboundary<strong>)<\/strong>\r\n415\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n416\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n417\r\n418\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Determine what kind of boundary.\r\n419\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> k<strong>;<\/strong>\r\n420\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">bool<\/span> isheavy<strong>;<\/strong>\r\n421\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>xcount <strong>&lt;<\/strong> ycount<strong>)<\/strong>\r\n422\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n423\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 k <strong>=<\/strong> xk<strong>;<\/strong>\r\n424\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 isheavy <strong>=<\/strong> xheavy<strong>;<\/strong>\r\n425\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n426\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong>\r\n427\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n428\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 k <strong>=<\/strong> yk<strong>;<\/strong>\r\n429\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 isheavy <strong>=<\/strong> yheavy<strong>;<\/strong>\r\n430\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n431\r\n432\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(!<\/strong>isheavy<strong>)<\/strong>\r\n433\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n434\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ L bits differ.\r\n435\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ back up before L.\r\n436\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> xmask <strong>=<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)-(<\/strong>1 <strong>&lt;&lt;<\/strong> j<strong>);<\/strong>\r\n437\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0ncalabel <strong>=<\/strong> xs <strong>&amp;<\/strong> xmask<strong>;<\/strong>\r\n438\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ncak <strong>=<\/strong> xk <strong>&amp;<\/strong> xmask<strong>;<\/strong>\r\n439\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n440\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong>\r\n441\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n442\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ H bits differ.\r\n443\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ First, back up before H.\r\n444\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ncalabel <strong>=<\/strong> xs <strong>&amp;<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)-(<\/strong>1 <strong>&lt;&lt;<\/strong> j<strong>);<\/strong>\r\n445\r\n446\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ move forward picking alphabetic minimum H bits\r\n447\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ until next L.\r\n448\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> xsm <strong>=<\/strong> xs<strong>;<\/strong>\r\n449\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> ysm <strong>=<\/strong> ys<strong>;<\/strong>\r\n450\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> xmask<strong>;<\/strong>\r\n451\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">uint<\/span> ymask<strong>;<\/strong>\r\n452\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n453\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Find specific masks to get prefix plus heavy label.\r\n454\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Scan ahead for 0-bit.\r\n455\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> i<strong>;<\/strong>\r\n456\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong>i <strong>=<\/strong> Bithacks<strong>.<\/strong>FloorLog2<strong>((<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)<\/strong>v<strong>);<\/strong> <strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n457\u00c2\u00a0\u00c2\u00a0 \u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0<strong>{<\/strong>\r\n458\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>((<\/strong>xk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>==<\/strong> 0<strong>)<\/strong>\r\n459\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n460\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n461\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 i<strong>++;<\/strong> \/\/ backup.\r\n462\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ get mask of all 1's up to heavy label and apply to the label.\r\n463\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xmask <strong>=<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)-(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>);<\/strong>\r\n464\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 xsm <strong>&amp;=<\/strong> xmask<strong>;<\/strong>\r\n465\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n466\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n467\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Find specific masks to get prefix plus heavy label.\r\n468\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Scan ahead for 0-bit.\r\n469\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <span style=\"text-decoration: underline;\">int<\/span> i<strong>;<\/strong>\r\n470\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">for<\/span><\/strong> <strong>(<\/strong>i <strong>=<\/strong> Bithacks<strong>.<\/strong>FloorLog2<strong>((<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)<\/strong>v<strong>);<\/strong> <strong>;<\/strong> <strong>--<\/strong>i<strong>)<\/strong>\r\n471\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n472\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>((<\/strong>yk <strong>&amp;<\/strong> <strong>(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>))<\/strong> <strong>==<\/strong> 0<strong>)<\/strong>\r\n473\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n474\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n475\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 i<strong>++;<\/strong> \/\/ backup.\r\n476\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ get mask of all 1's up to heavy label and apply to the label.\r\n477\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ymask <strong>=<\/strong> <strong>(<\/strong><span style=\"text-decoration: underline;\">uint<\/span><strong>)-(<\/strong>1 <strong>&lt;&lt;<\/strong> i<strong>);<\/strong>\r\n478\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ysm <strong>&amp;=<\/strong> ymask<strong>;<\/strong>\r\n479\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n480\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 \/\/ Got two labels, pick the one that is alphabetic.\r\n481\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>xsm <strong>&lt;<\/strong> ysm<strong>)<\/strong>\r\n482\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n483\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ncalabel <strong>=<\/strong> xsm<strong>;<\/strong>\r\n484\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ncak <strong>=<\/strong> xk <strong>&amp;<\/strong> xmask<strong>;<\/strong>\r\n485\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n486\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">else<\/span><\/strong>\r\n487\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n488\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ncalabel <strong>=<\/strong> ysm<strong>;<\/strong>\r\n489\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 ncak <strong>=<\/strong> yk <strong>&amp;<\/strong> ymask<strong>;<\/strong>\r\n490\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n491\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n492\r\n493\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 Vertex found <strong>=<\/strong> <strong><span style=\"text-decoration: underline;\">null<\/span><\/strong><strong>;<\/strong>\r\n494\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">foreach<\/span><\/strong> <strong>(<\/strong>KeyValuePair<strong>&lt;<\/strong>Vertex<strong>,<\/strong> <span style=\"text-decoration: underline;\">uint<\/span><strong>&gt;<\/strong> match <strong><span style=\"text-decoration: underline;\">in<\/span><\/strong> <strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>labelEncodingBinary<strong>)<\/strong>\r\n495\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n496\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong>match<strong>.<\/strong>Value <strong>==<\/strong> ncalabel<strong>)<\/strong>\r\n497\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n498\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">if<\/span><\/strong> <strong>(<\/strong><strong><span style=\"text-decoration: underline;\">this<\/span><\/strong><strong>.<\/strong>kEncodingBinary<strong>[<\/strong>match<strong>.<\/strong>Key<strong>]<\/strong> <strong>==<\/strong> ncak<strong>)<\/strong>\r\n499\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>{<\/strong>\r\n500\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 found <strong>=<\/strong> match<strong>.<\/strong>Key<strong>;<\/strong>\r\n501\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">break<\/span><\/strong><strong>;<\/strong>\r\n502\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n503\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n504\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n505\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong><span style=\"text-decoration: underline;\">return<\/span><\/strong> found<strong>;<\/strong>\r\n506\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n507\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0\u00c2\u00a0 <strong>}<\/strong>\r\n508 <strong>}<\/strong>\r\n509\r\n<\/code><\/pre>\n<p><span style=\"text-decoration: underline;\">Example<\/span><\/p>\n<p>Figure 4. Finding the nearest common ancestor using the Alstrup-Gavoille-Kaplan-Rauhe algorithm.<\/p>\n<p><img loading=\"lazy\" class=\"aligncenter size-medium wp-image-134\" title=\"LCA6\" src=\"http:\/\/domemtech.com\/wordpress\/wp-content\/uploads\/2009\/07\/LCA6-278x300.png\" alt=\"LCA6\" width=\"278\" height=\"300\" \/><\/p>\n<p><script type=\"text\/javascript\"><\/script><\/p>\n<p>Consider the example tree displayed in Figure 4.\u00c2\u00a0 Compute the nearest common ancestor of nodes <em>F<\/em> and <em>N<\/em>.<\/p>\n<p>In a series of passes over the tree, the algorithm performs preprocessing (lines 40-58): <em>Size<\/em>(<em>v<\/em>) at lines 42 and 60-71; <em>IsHeavy<\/em>(<em>v<\/em>) at lines 43, 44, and 149-179; <em>Apex<\/em>(<em>v<\/em>) at lines 45 and 181-199; <em>HeavyLabel<\/em>(<em>v<\/em>) at lines 46-49 and 201-216; <em>LightLabel<\/em>(<em>v<\/em>) at lines 50 and 218-226; <em>EncodeHeavyLabel<\/em>(<em>v<\/em>) at lines 51-54 and 228-272; <em>EncodeLightLabel<\/em>(<em>v<\/em>) at lines 56 and 274-310; and <em>FullLabel<\/em>(<em>v<\/em>) at lines 57 and 73-147.\u00c2\u00a0 The results of the computation are displayed in Table 3.<\/p>\n<p>The NCA for nodes <em>F<\/em> and <em>N<\/em> is now computed (lines 312-508).\u00c2\u00a0 The full labels for the two nodes are found (lines 326 and 327).\u00c2\u00a0 <em>FullLabel<\/em>(<em>F<\/em>) = 5800<sub>16<\/sub>.\u00c2\u00a0 <em>FullLabel<\/em>(<em>N<\/em>) = 7000<sub>16<\/sub>.\u00c2\u00a0 <em>FullLabel<\/em>(<em>NCA<\/em>(<em>F<\/em>, <em>N<\/em>)) = <em>FullLabel<\/em>(<em>F<\/em>) &amp; <em>FullLabel<\/em>(<em>N<\/em>) = 5800<sub>16 <\/sub> &amp; 7000<sub>16<\/sub> = 5000<sub>16<\/sub>.\u00c2\u00a0 <em>Mask<\/em>(<em>F<\/em>) = D800<sub>16<\/sub>.\u00c2\u00a0 <em>Mask<\/em>(<em>N<\/em>) = F400<sub>16<\/sub>.\u00c2\u00a0 The most significant bit that is different is bit 13 (bit 0 is the least significant bit, bit 15 is the most significant), found at line 331.\u00c2\u00a0 This bit corresponds to a bit difference in the heavy label substring of <em>FullLabel<\/em>(<em>N<\/em>) but in the light label substring of <em>FullLabel<\/em>(<em>F<\/em>) (lines 343-344).\u00c2\u00a0 The number of heavy\/light substring boundary crossings is next counted starting from the left edge of each full label, xcount = 2, ycount = 1 (lines 348-403). The bit that is different is on a heavy\/light substring boundary for <em>FullLabel<\/em>(<em>N<\/em>), but not for <em>FullLabel<\/em>(<em>F<\/em>).\u00c2\u00a0 All this information leads one to conclude that the bit that is different is in the heavy label substring of <em>FullLabel<\/em>(<em>N<\/em>).\u00c2\u00a0 In this case, the minimum between the two heavy label substrings must be chosen (lines 441-491).\u00c2\u00a0 The labels are computed and compared (line 481) and the <em>FullLabel<\/em>(<em>NCA<\/em>(<em>F<\/em>, <em>N<\/em>)) = 4000<sub>16<\/sub>.\u00c2\u00a0 Therefore, <em>NCA<\/em>(<em>F,<\/em> <em>N<\/em>) = <em>Reverse<\/em>(<em>FullLabel<\/em>(<em>NCA<\/em>(<em>F<\/em>, <em>N<\/em>))) = <em>Reverse<\/em>(4000) = <em>B<\/em> (line 500).<\/p>\n<p>Table 3.\u00c2\u00a0 Alstrup-Gavoille-Kaplan-Rauhe computation for Figure 4.<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n<tbody>\n<tr>\n<td width=\"6%\" valign=\"top\">Node, v<\/td>\n<td width=\"6%\" valign=\"top\">Size(v)<\/td>\n<td width=\"7%\" valign=\"top\">Class(v)<\/td>\n<td width=\"6%\" valign=\"top\">Light label(v)<\/td>\n<td width=\"7%\" valign=\"top\">Encoded Light label(v)<\/td>\n<td width=\"6%\" valign=\"top\">Heavy label(v)<\/td>\n<td width=\"7%\" valign=\"top\">Encoded Heavy label(v)<\/td>\n<td width=\"22%\" valign=\"top\">Label definition<\/td>\n<td width=\"11%\" valign=\"top\">Full Label with light and heavy   boundary indicators<\/td>\n<td width=\"7%\" valign=\"top\">Full Label (16-bit value)<\/td>\n<td width=\"9%\" valign=\"top\">Heavy\/light regions (16-bit value)<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">A<\/td>\n<td width=\"6%\" valign=\"top\">18<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">18<\/td>\n<td width=\"7%\" valign=\"top\">e<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">00000<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(A)<\/td>\n<td width=\"11%\" valign=\"top\">LH00000<\/td>\n<td width=\"7%\" valign=\"top\">0000<\/td>\n<td width=\"9%\" valign=\"top\">F800<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">B<\/td>\n<td width=\"6%\" valign=\"top\">17<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">11<\/td>\n<td width=\"7%\" valign=\"top\">01<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B)<\/td>\n<td width=\"11%\" valign=\"top\">LH01<\/td>\n<td width=\"7%\" valign=\"top\">4000<\/td>\n<td width=\"9%\" valign=\"top\">C000<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">C<\/td>\n<td width=\"6%\" valign=\"top\">4<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">4<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"6%\" valign=\"top\">3<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(C).H(C)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L0H0<\/td>\n<td width=\"7%\" valign=\"top\">4000<\/td>\n<td width=\"9%\" valign=\"top\">D000<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">D<\/td>\n<td width=\"6%\" valign=\"top\">6<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">2<\/td>\n<td width=\"7%\" valign=\"top\">0110<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(D)<\/td>\n<td width=\"11%\" valign=\"top\">LH0110<\/td>\n<td width=\"7%\" valign=\"top\">6000<\/td>\n<td width=\"9%\" valign=\"top\">F000<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">E<\/td>\n<td width=\"6%\" valign=\"top\">6<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">6<\/td>\n<td width=\"7%\" valign=\"top\">1<\/td>\n<td width=\"6%\" valign=\"top\">2<\/td>\n<td width=\"7%\" valign=\"top\">00<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(E).H(E)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L1H00<\/td>\n<td width=\"7%\" valign=\"top\">6000<\/td>\n<td width=\"9%\" valign=\"top\">D800<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">F<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">11<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(C).H(F)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L0H11<\/td>\n<td width=\"7%\" valign=\"top\">5800<\/td>\n<td width=\"9%\" valign=\"top\">D800<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">G<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(C).H(C).L(G).H(G)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L0H0L0H0<\/td>\n<td width=\"7%\" valign=\"top\">4000<\/td>\n<td width=\"9%\" valign=\"top\">D400<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">1<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(C).H(C).L(H).H(H)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L0H0L1H0<\/td>\n<td width=\"7%\" valign=\"top\">4800<\/td>\n<td width=\"9%\" valign=\"top\">D400<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">I<\/td>\n<td width=\"6%\" valign=\"top\">4<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">3<\/td>\n<td width=\"7%\" valign=\"top\">0111<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(I)<\/td>\n<td width=\"11%\" valign=\"top\">LH0111<\/td>\n<td width=\"7%\" valign=\"top\">7000<\/td>\n<td width=\"9%\" valign=\"top\">F000<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">J<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(D).L(J).H(J)<\/td>\n<td width=\"11%\" valign=\"top\">LH0110L0H0<\/td>\n<td width=\"7%\" valign=\"top\">6000<\/td>\n<td width=\"9%\" valign=\"top\">F400<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">K<\/td>\n<td width=\"6%\" valign=\"top\">4<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">3<\/td>\n<td width=\"7%\" valign=\"top\">01<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(E).H(K)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L1H01<\/td>\n<td width=\"7%\" valign=\"top\">6800<\/td>\n<td width=\"9%\" valign=\"top\">D800<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(E).H(E).L(L).H(L)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L1H00L0H0<\/td>\n<td width=\"7%\" valign=\"top\">6000<\/td>\n<td width=\"9%\" valign=\"top\">Da00<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">M<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">10001<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(M)<\/td>\n<td width=\"11%\" valign=\"top\">LH10001<\/td>\n<td width=\"7%\" valign=\"top\">8800<\/td>\n<td width=\"9%\" valign=\"top\">F800<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">N<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(I).L(N).H(N)<\/td>\n<td width=\"11%\" valign=\"top\">LH0111L0H0<\/td>\n<td width=\"7%\" valign=\"top\">7000<\/td>\n<td width=\"9%\" valign=\"top\">F400<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">O<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">1<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(I).L(O).H(O)<\/td>\n<td width=\"11%\" valign=\"top\">LH0111L1H0<\/td>\n<td width=\"7%\" valign=\"top\">7800<\/td>\n<td width=\"9%\" valign=\"top\">F400<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">P<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">H<\/td>\n<td width=\"6%\" valign=\"top\">&#8211;<\/td>\n<td width=\"7%\" valign=\"top\"><\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">101<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(E).H(P)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L1H101<\/td>\n<td width=\"7%\" valign=\"top\">7400<\/td>\n<td width=\"9%\" valign=\"top\">Dc00<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">Q<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(E).H(K).L(Q).H(Q)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L1H01L0H0<\/td>\n<td width=\"7%\" valign=\"top\">6800<\/td>\n<td width=\"9%\" valign=\"top\">Da00<\/td>\n<\/tr>\n<tr>\n<td width=\"6%\" valign=\"top\">R<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">L<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">1<\/td>\n<td width=\"6%\" valign=\"top\">1<\/td>\n<td width=\"7%\" valign=\"top\">0<\/td>\n<td width=\"22%\" valign=\"top\">L(A).H(B).L(E).H(K).L(R).H(R)<\/td>\n<td width=\"11%\" valign=\"top\">LH01L1H01L1H0<\/td>\n<td width=\"7%\" valign=\"top\">6c00<\/td>\n<td width=\"9%\" valign=\"top\">Da00<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>References<\/p>\n<p>[1] Aho, A., Hopcroft, J. and Ullman, J. On finding lowest common ancestors in trees. <em>SIAM J. Comput.<\/em>, 51976), 115-132.<\/p>\n<p>[2] Gusfield, D. Algorithms on Stings, Trees, and Sequences: Computer Science and Computational Biology. <em>ACM SIGACT News<\/em>, 28, 4 1997), 41-60.<\/p>\n<p>[3] Farach, M., Kannan, S. and Warnow, T. A robust model for finding optimal evolutionary trees. <em>Algorithmica<\/em>, 13, 1 1995), 155-179.<\/p>\n<p>[4] Walker II, J. A Node-positioning Algorithm for General Trees. <em>Software &#8211; Practice and Experience<\/em>, 20, 7 1990), 685-705.<\/p>\n<p>[5] Di Battista, G. and Tamassia, R. On-line planarity testing. <em>SIAM Journal on Computing<\/em>, 251996), 956-997.<\/p>\n<p>[6] Westbrook, J. <em>Fast incremental planarity testing<\/em>. Springer, City, 1992.<\/p>\n<p>[7] Harel, D. and Tarjan, R. Fast algorithms for finding nearest common ancestors. <em>SIAM Journal on Computing<\/em>, 131984), 338.<\/p>\n<p>[8] Knuth, D. <em>Combinatorial Algorithms<\/em>. City, 2008.<\/p>\n<p>[9] Alstrup, S., Gavoille, C., Kaplan, H. and Rauhe, T. <em>Nearest common ancestors: A survey and a new distributed algorithm<\/em>. ACM New York, NY, USA, City, 2002.<\/p>\n<p>[10] Alstrup, S., Gavoille, C., Kaplan, H. and Rauhe, T. Nearest common ancestors: A survey and a new algorithm for a distributed environment. <em>Theory of Computing Systems<\/em>, 37, 3 2004), 441-456.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post is about computing the nearest common ancestor.\u00c2\u00a0 It is the result of a month or so of reading papers and implementation.\u00c2\u00a0 Although there has been a lot of research into the problem, there are no implementations online of the two main algorithms presented.\u00c2\u00a0 Worse, examples in the papers are practically useless.\u00c2\u00a0 For example, &hellip; <\/p>\n<p class=\"link-more\"><a href=\"http:\/\/165.227.223.229\/index.php\/2009\/07\/25\/computing-the-nearest-common-ancestor\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Computing the nearest common ancestor&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/91"}],"collection":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/comments?post=91"}],"version-history":[{"count":0,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/posts\/91\/revisions"}],"wp:attachment":[{"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/media?parent=91"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/categories?post=91"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/165.227.223.229\/index.php\/wp-json\/wp\/v2\/tags?post=91"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}