{"id":29101966,"url":"https://github.com/tyilo/link_cut_tree","last_synced_at":"2025-10-14T03:46:23.960Z","repository":{"id":144985519,"uuid":"188981252","full_name":"tyilo/link_cut_tree","owner":"tyilo","description":"A link/cut tree implemented in python","archived":false,"fork":false,"pushed_at":"2020-01-29T15:49:17.000Z","size":23,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-06-28T21:09:05.362Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tyilo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2019-05-28T07:53:48.000Z","updated_at":"2024-07-29T01:29:58.000Z","dependencies_parsed_at":"2023-03-29T00:48:01.786Z","dependency_job_id":null,"html_url":"https://github.com/tyilo/link_cut_tree","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/tyilo/link_cut_tree","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Flink_cut_tree","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Flink_cut_tree/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Flink_cut_tree/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Flink_cut_tree/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tyilo","download_url":"https://codeload.github.com/tyilo/link_cut_tree/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tyilo%2Flink_cut_tree/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279017782,"owners_count":26086145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-06-28T21:08:58.401Z","updated_at":"2025-10-14T03:46:23.955Z","avatar_url":"https://github.com/tyilo.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# link_cut_tree\n\nA link/cut tree implemented in python.\n\nAll link/cut tree operations on a node are prefixed with `lc_`.\nOther methods are splay tree operations on the auxiliary tree.\n\nSupports the following operations in `O(log n)` amortized time, where `v` and `w` are nodes:\n\n- `v.lc_get_root()`\n- `v.lc_cut()`\n- `v.lc_link(w)`\n- `v.lc_path_aggregate()`\n- `v.lc_evert()`\n- `v.lc_lca(w)`\n\n## Path aggregation\n\nTo support path aggregation extra information must be stored on the nodes.\nThis can be done by making a subclass of `Node` and overriding `update_augmentation`.\n\n### Min example\n\nTo support querying the minimum value in a path, the following class can be used:\n\n```python\nclass PathMinNode(Node):\n    def update_augmentation(self):\n        self.augmentation = self.value\n        for c in self.children:\n            if c:\n                self.augmentation = min(self.augmentation, c)\n```\n\nNow `v.lc_path_aggregate()` can be used to query the minimum value on the path from `v` to the root in the represented tree.\n\n## Advanced augmentation\n\nInstead of just overriding `update_augmentation`, you can also override `_rotate_up`, `_lc_replace_right_subtree` and `lc_link` to support some more advanced forms of augmentation.\n\nIn `test/test_subtree_sum.py` is an example of a link/cut tree, where each node is augmented with the sum of its subtree's values in the represented tree. Note that this is vastly different from just a simple path aggregation.\n\nThe nodes supports the following operations in `O(log n)` amortized time:\n\n- `v.get_sum()`: Returns the subtree sum for `v`.\n- `v.set_value(value)`: Sets the value of `v` to `value`. (Subtree sums will be updated).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyilo%2Flink_cut_tree","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftyilo%2Flink_cut_tree","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftyilo%2Flink_cut_tree/lists"}