(root, tree)
| 11 | |
| 12 | export class BinaryLifting { |
| 13 | constructor(root, tree) { |
| 14 | this.root = root |
| 15 | this.connections = new Map() |
| 16 | this.up = new Map() // up[node][i] stores the 2^i-th parent of node |
| 17 | for (const [i, j] of tree) { |
| 18 | this.addEdge(i, j) |
| 19 | } |
| 20 | this.log = Math.ceil(Math.log2(this.connections.size)) |
| 21 | this.dfs(root, root) |
| 22 | } |
| 23 | |
| 24 | addNode(node) { |
| 25 | // Function to add a node to the tree (connection represented by set) |