Union finds the roots of components for two nodes, compares the components in terms of size, and attaches the smaller one to the larger one to form single component
(self, component_size: list[int], u_node: int, v_node: int)
| 66 | self.m_component[k] = self.find_component(k) |
| 67 | |
| 68 | def union(self, component_size: list[int], u_node: int, v_node: int) -> None: |
| 69 | """Union finds the roots of components for two nodes, compares the components |
| 70 | in terms of size, and attaches the smaller one to the larger one to form |
| 71 | single component""" |
| 72 | |
| 73 | if component_size[u_node] <= component_size[v_node]: |
| 74 | self.m_component[u_node] = v_node |
| 75 | component_size[v_node] += component_size[u_node] |
| 76 | self.set_component(u_node) |
| 77 | |
| 78 | elif component_size[u_node] >= component_size[v_node]: |
| 79 | self.m_component[v_node] = self.find_component(u_node) |
| 80 | component_size[u_node] += component_size[v_node] |
| 81 | self.set_component(v_node) |
| 82 | |
| 83 | def boruvka(self) -> None: |
| 84 | """Performs Borůvka's algorithm to find MST.""" |
no test coverage detected