Home > Enterprise >  Time limit exceeded when finding tree height
Time limit exceeded when finding tree height

Time:05-28

this is my code to find the height of a tree of up to 10^5 nodes. May I know why I get the following error?

Warning, long feedback: only the beginning and the end of the feedback message is shown, and the middle was replaced by " ... ". Failed case #18/24: time limit exceeded

Input: 100000

Your output: stderr: (Time used: 6.01/3.00, memory used: 24014848/2147483648.)

Is there a way to speed up this algo?

This is the exact problem description:

Problem Description Task. You are given a description of a rooted tree. Your task is to compute and output its height. Recall that the height of a (rooted) tree is the maximum depth of a node, or the maximum distance from a leaf to the root. You are given an arbitrary tree, not necessarily a binary tree.

Input Format. The first line contains the number of nodes

  • Related