[Community Puzzle] Longest Road

Hope to add the maximum number of players in the problem description(Translated by Google)

after some hours, i have managed to code DFS algo with a success for all tests.
No cheat, everything is calculated

but when I submit, test 4 and 6 and non validatedā€¦
Cold you help me ?

Did you try this custom case? (Check out the original post to see the custom case properly formatted.)

You could also try creating your own custom cases to test your code, e.g. by flipping the grid horizintally or vertically.

1 Like

thank you for your prompt answer @5DN1L
it works with this example too.

By the way test 4 is now validated in submission tooā€¦ but i have changed nothing!

okā€¦ i go back to work and i will try tonightā€¦ let see

Thank you again @5DN1L !!

[quote="[Community Puzzle] Longest Road, post:22, topic:190734"]
aA##c #a##c b###C bBb#c ##bcc
[/quote]

1 Like

pb solved :slight_smile:

so happy

1 Like

Hi there, great puzzle to work on your fundamentals i.e., not too long, nor too hard, but with some twists to keep it interesting.

I have come into a bit of a headache with validator6 which was the only failing test, it must have an interesting edge case, that should be implemented in the regular test case for exhaustivity.

Haha, but nope, itā€™s not an edge case. The validator is a mirror image of the test case and two chars changed (road<->empty). :smile:

1 Like

Hello, my code does not pass the last validator 6, for each related component (one per character) I search the diameter of the spanning tree with two successive dfs, is it a false lead? My code works for the 5DN1L example with C 5. What is the particularity of the last validator?

Very fun puzzle overall.
Yet another puzzle showing how absurdly powerful recursive functions are.

2 Likes

Please refer to this answer:

1 Like

Thanks, problem solved. My algo of diameter search by related component cannot work because some nodes count in the distance calculation and others do not. A calculation running a dfs from all possible nodes is enough.

2 Likes

Isnā€™t this puzzle, in the general case, as difficult as Longest path problem - Wikipedia, i.e. NP-hard?

I donā€™t have a formal background in CS so I could be wrong, but to my understanding a problem being NP-hard, NP-complete, etc. simply refers to the amount of computational time required to find a solution. The difficulty of the problem does not necessarily relate to the amount of time an algorithm takes to solve the problem. This puzzle and its test cases were designed to be solved with basic recursion algorithms without running into timeouts. So I would not say it is as difficult in general especially compared to java_coffee_cupā€™s example, but it is a very similar problem.

Yes, the puzzle design allows some very difficult situations that is too hard to solve within the time limit. That difficult situation currently does not appear in test cases but theoretically it can appear and nothing can stop it to appear.

This potential problem can be reduced by defining some constraints to restrain the search space to a reasonable range.