Zahid_Hasan_Sahin's blog

By Zahid_Hasan_Sahin, history, 4 weeks ago, In English

I'm trying to solve Farthest Nodes in a Tree (II) Problem in java . it's from lightOj. But I'm getting MLE(it takes 151552 KB memory). How to solve it using java.??

code:

UPD:Using System.gc() after each testCase I have got AC.

 
 
 
 
  • Vote: I like it
  • 0
  • Vote: I do not like it

»
4 weeks ago, # |
  Vote: I like it 0 Vote: I do not like it

Try writing iterative dfs, or maybe just write a bfs instead.

  • »
    »
    4 weeks ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    Again MLE.memory used 151552 KB.

    code:
    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      In the future, I would suggest you use Java's StringTokenizer and BufferedReader. Java's Scanner class is notoriously known for getting TLE or faster runtimes.

      • »
        »
        »
        »
        4 weeks ago, # ^ |
          Vote: I like it 0 Vote: I do not like it

        I use fast i/o.but for Simplicity i have share this code without any extra code.Btw my problem isn't TLE, problem is MLE. :(