For the problem ROADTRIP, my solution is failing for three testcases

This code, which is almost the same as my code, has gotten AC.

What’s the problem with my code?

For the problem ROADTRIP, my solution is failing for three testcases

This code, which is almost the same as my code, has gotten AC.

What’s the problem with my code?

If answer is -1 then you aren’t clearing your arrays and stuff ig

1 Like

I did clear the arrays. I even tried clearing the whole array just in case.

You are not clearing

Check it once again

```
for(int i = 0; i < MAX; i++){
museums[i] = 0;
visited[i] = false;
graph[i].clear();
}
```

I’m making `visited[i] = false;`

each time

Ohhh, okay, I got it. Thanks for your help guys!

Why did it give AC now, you cleared everything just as each test-case start, earlier you were clearing after each test-case-starts…whats the actual difference ?

If the answer was -1, the graph wouldn’t be cleared

If I clear it before the testcase starts, no matter the result for the previous testcase, the graph would be cleared

Can anyone tell me if there is something else to this question other than bfs and dfs. I tried implementing both but I am getting TLE each time.

Can you please send your implementation? (Of the DFS)

1 Like

nvm. I got it. It was my implementation which was bad. Thanks!