Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

F-Talent 2021 18/09/2021 R.

Tree Height

R. Tree Height
Time Limit: 3 seconds
Problem description
×
Given the ancestor Matrix 𝐴 ∈ ℝ of 𝑁 nodes. 𝐴 , = 1 if node 𝑖 is a child node of 𝑖 .

Your task is to write a program to compute the height of the Tree that represented by 𝐴.
Example:
0 1 1 1
𝐴= 0 0 0
0 0 0
2 3
Tree heigh is 2.

Input:
The first line of the input indicates the number of nodes (0 < n <= 10).
The rest represents the ancestor matrix.

Output:
An integer number represents the tree height
Examples:
Input Output
3 2
011
000
000
5 3
00000
00000
01001
10100
00000

Page 1 of 1

You might also like