This question evaluates a candidate's ability to design and implement complex graph-based data structures and algorithms, including representation of a family DAG with constraints, cycle detection, ancestor/descendant queries, DAG-based closest-common-ancestor computation, dynamic parent/child linking and unlinking, indexing for fast queries, and serialization while considering performance targets for N ≤ 1e5 and Q ≤ 1e5. It is commonly asked in the Coding & Algorithms domain to assess proficiency in graph theory, algorithmic complexity and trade-offs, incremental update and cycle-detection strategies, and both conceptual understanding of DAG semantics and practical application of scalable, online data-structure design.
设计一个族谱树(家谱)数据结构来表示血缘关系:每个 Person 节点具有唯一 id、姓名、可选出生/死亡年份与性别;每个节点至多关联两位父母,允许多个子女;整体应为有向无环图(父母→子女),禁止形成环。需要支持以下操作并给出关键函数的伪代码、时间/空间复杂度分析与单元测试样例: