Method
valid_tree
(self, n: int, edges: List[List[int]])
Source from the content-addressed store, hash-verified
| 58 | self.components -= 1 |
| 59 | |
| 60 | def valid_tree(self, n: int, edges: List[List[int]]) -> bool: |
| 61 | # init here as not sure that ctor will be re-invoked in different tests |
| 62 | self.parents = {} |
| 63 | self.heights = {} |
| 64 | self.components = n |
| 65 | |
| 66 | for e1, e2 in edges: |
| 67 | if self.__find(e1) == self.__find(e2): # 'redundant' edge |
| 68 | return False |
| 69 | self.__connect(e1, e2) |
| 70 | |
| 71 | return self.components == 1 # forest contains one tree |
| 72 | |
| 73 | |
Callers
nothing calls this directly
Tested by
no test coverage detected