OlveraeUNSW
Back to problems
COMP2521

21T3 Q7 — Is the digraph a binary tree?

stdin: N, then an N×N adjacency matrix of a directed graph (1 = edge i→j). Print true iff it is a binary tree: exactly one root (in-degree 0), every other vertex in-degree 1, every vertex out-degree ≤ 2, and every vertex reachable from the root; otherwise false.


Single-file C (gcc -O0 -Wall). Self-contained reframing of the exam's ADT-completion question. From COMP2521 21T3 Sample.

Samples

stdin
5
0 1 1 0 0
0 0 0 1 1
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
expected
true
c-gcc
14