Union-Find Structure The union-find data structure is a tree-based structure designed to efficiently manage disjoint sets through two primary operations: Find Operation: Determines which subset a particular element belongs to Union Operation: Merges two subsets into a single set int parent[N]; // Ea...
Problem Overview The prisoners problem involves assigning prisoners to two cells such that prisoners with high hostility are separated. Each prisoner has a hostility level with other prisoners, and we need to find the maximum hsotility level that can be guaranteed to separate. Solution 1: Union-Find...
Problem Context An island has two types of inhabitants: truth-tellers, who always tell the truth, and liars, who always lie. Each inhabitent has a unique integer identifier. You are allowed n questions. Each question must be direcetd to one inhabitant, asking whether another inhabitant is a truth-te...
2023.10.19 Full Simulation Exam Summary Overview Schedule Exam Results Exam Reflection Problems T1 T2 T3 T4 Overview Schedule 8 : 00 ∼ 8 : 20 \qquad 8:00\sim 8:20 8:00∼8:20 Read through the problem statements, and got a general idea of each question in my mind, thinking briefly. The exam felt very f...
Binary Tree Implemented with Option<Box<T>>. Box is a smart pointer that allocates on the heap, ideal for recursive types that would ohterwise have unbounded size. LeetCode often uses Option<Rc<RefCell<T>>>, which is quite bloated. #[derive(PartialEq)] enum ChildSide {...
Understanding Union-Find Union-Find is a data structure designed to manage relationships between sets, enabling operasions like determining set membership and merging distinct sets. Consider a practical scenario: Initially, Xiao Ming belongs to one family set and Xiao Hong to another. When they marr...
Graph Connectivity Using Union-Find The problem involves determining whether a path exists between two nodes in an undirected graph represented by edge pairs. While traditional graph search algorithms like BFS or DFS could solve this, the Union-Find data structure provides a more efficient approach...
Coordinate Linearization for Grid Structures To efficiently apply disjoint set operations on a two-dimensional matrix of dimensions $H \times W$, encode each cell position $(r, c)$ into a scalar identifier using the formula $id = r \times W + c$. This mapping establishes a bijection between matrix c...
Two notable problems involving permutation group subgroups are determining the subgroup order (e.g., LOJ177) and counting inversions (e.g., Grupa Permutacji). Surprisingly, both admit polynomial-time solutions, leveraging a key property of "uniformity" in the generated subgroup. Uniformity...
Union-Find is a tree-based data structure designed to handle disjoint sets, supporting operations like merging two sets and querying connectivity. It efficiently addresses problems involving connectivity and merging of non-overlapping collections. In Union-Find, each set is represented as a tree whe...