stdin:N,随后 N×N 有向图邻接矩阵(1 表示 i→j 边)。当且仅当它是二叉树时打印 true:恰一个根(入度 0),其余顶点入度均为 1,所有顶点出度 ≤ 2,且根可达所有顶点;否则 false。
Single-file C (gcc -O0 -Wall). Self-contained reframing of the exam's ADT-completion question. From COMP2521 21T3 Sample.
stdin:N,随后 N×N 有向图邻接矩阵(1 表示 i→j 边)。当且仅当它是二叉树时打印 true:恰一个根(入度 0),其余顶点入度均为 1,所有顶点出度 ≤ 2,且根可达所有顶点;否则 false。
Single-file C (gcc -O0 -Wall). Self-contained reframing of the exam's ADT-completion question. From COMP2521 21T3 Sample.