[Community Puzzle] Plague, Jr

Considering the puzzle tags, I suggest you look into the basics of graph theory

1 Like

Hi,
please donā€™t give the solution, youā€™re hint was very good and let people search.
Thank you

Hello all,
I tried this puzzle in C and passed all the tests, but 0% when I submitted my code.
I went into the contribution section and hit the ā€˜test in IDEā€™ button to run both tests and validators: I pass them all.
I donā€™t have this with any other puzzle, so far.
Anyone knows this, please?
Thank you

IDE tests are run in debug mode and validators in release mode. Weā€™re assuming you have a memory issue.

You may be right, thank you.
I use ad-aware browser no more supported with hundreds of tabs, and my computer is on for days. Despite, memory usage is 55% and swap usage 30%, and still I can submit my code for other puzzles. Anyway, Iā€™ll switch it off and try again later, Iā€™ll let you know if it continues.
Thank you

An accurate description is not ā€œholding your handā€. The other puzzles on CodinGame, for the most part, have clear, accurate descriptions. ā€œAssumingā€ an ideal starting point is not as clear as, for example, ā€œOut of all possible starting pointsā€¦ā€

LOL :rofl:
I spend enough time correcting them to have a fair idea of the general level.

In any case, thank you for writing out your rewording suggestions. I donā€™t wish to merge it in the statement, but theyā€™ll certainly help someone by being here.

1 Like

In other words, you prefer to keep a less accurate description even when you see that more than one person has to come here to clarify.

ā€œLess accurateā€ is merely your opinion, Iā€™m afraid. You might share it with 3 people in this thread, but it was fine for myself, all three independent moderators who approved it, and the 130 other CodinGamers who solved it. The arguments you used in your debating here, for now, have only comforted me in my opinion.

Let it be clear that I do think itā€™s less clear. And thatā€™s the point.

My solution is essentially just performing a BFS on each of the nodes to find the one that requires the smallest depth to traverse them all. With BFS, you should most likely be using the deque from the collections package so that you can push and pop from opposite ends of the queue in an efficient manner (itā€™s a doubly linked list).

Another trick is to keep track of the smallest depth found thus far, and short-circuit any ā€œtrialsā€ that reach that depth because you know they wonā€™t be any shorter and can thus continue to another node to start from without fully simulating a longer infection.

Essentially:

  • Keep track of current min
  • For each node:
    • Simulate infection with BFS
    • While simulating, if infection nights >= current min, stop
    • Otherwise, current min = infection nights
  • Tada
2 Likes

This puzzle reminded me of the Teads sponsored medium training puzzle that I solved 2 months ago. While I donā€™t find that puzzle on the site anymore, I have the saved the code.
Interestingly it tests/validates to 80% without any modification at Plague Jr test, but with ā€œadvanced caseā€ I find graph diameter of ā€œ10ā€ vs the expected answer of 13.
Now I am stuck: I donā€™t find the real difference between the two puzzle problems and I donā€™t understand why 13 is the answer to this case (though I admit I did not draw the graph of 999 vertices).
Any hint from experts?

The Teads puzzle disappeared (was a sponsored one).
So JBM made a completely new puzzle without any reference to possibly existing ones :smiley:
I would guess, that your solution to the original Teads had a bug not covered by the given testcases back then.

Hey Iā€™m completly stuck ā€¦ solved all cases but the advanced one. Iā€™m finding a solution in only 5 nights instead of 13ā€¦ what am I doing wrong ? Iā€™m using a tree diameter method.

Why canā€™t I use networkx ? It complains with ModuleNotFoundError: No module named ā€˜networkxā€™

Isnā€™t it pretty standard ?

@thanos.a Your question is not specific to this puzzle and you should mention the language when asking such a question (Python). The available libs are listed in the FAQ. networkx is not particularly ā€œstandardā€ and solving puzzles by calling libs that do all the job to the rescue is arguably not very interesting.

2 Likes

Thanks a lot for the suggestions and the link.

Thank you - recursion limit was stumping me

Hello, thx for the tip, however i donā€™t get it with your sentence ā€œYou donā€™t need to tell which node is in the centerā€.
Isnā€™t it the aim of computing diameter to find the optimal starting node ?
The goal is to find the node with the littlest maximum length with all other nodes, right ?

To use your words, the goal is only to find ā€œthe littlest maximum length with all other nodesā€. (see the difference?)

It could possibly help to find ā€œtheā€ node as well, but itā€™s not a requirement from the puzzle statement itself.

1 Like

OOOOOOOOOOOhhhhhhhhhhhhhhhhhhh (imagine the ā€œaliensā€ in toy story)

I think i get it, no need to use a ā€œspreadā€ machinary, as long as you can guess the less time it should take to link the farest nodes.

thx a lot, it saves a lot of computing time moreover.