i_am_bug's blog

By i_am_bug, history, 4 years ago, In English

problem-https://cses.fi/problemset/task/1193/ code-Your text to link here... Time Limit exceed

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

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

By looking at your code I guess you are visiting the same cell many times to find the shortest path from A to B and it is causing TLE. You can use the bfs to find the shortest path easily without visiting the same cell many times.

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

    Can this problem solve using DFS?

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

      I don't remember the question properly but I think it was not necessary to find the shortest path from A to B. I am not sure but I think you can solve it using dfs

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

      I don't think you can as you're finding the shortest path. Your visited array isn't being used.