28std::vector<int> adj[MAX];
29std::vector<bool> visited;
35 for (
int v : adj[u]) {
40 child_height = std::max(child_height,
dp[v] + 1);
50 std::cout <<
"Enter number of nodes of the tree : " << std::endl;
51 std::cin >> number_of_nodes;
56 std::cout <<
"Enter edges of the tree : " << std::endl;
57 for (
int i = 0; i < number_of_nodes - 1; i++) {
64 visited.assign(number_of_nodes + 1,
false);
66 dp.assign(number_of_nodes + 1, 0);
69 std::cout <<
"Height of the Tree : " <<
dp[1] << std::endl;
Functions for Depth First Search algorithm.