Excellent problem. Kudos to the author for setting such a problem. But on the other hand, I think the statement was quite convoluting. Please try to make the statements less complex, or give more explanations to examples if the first one can’t be achieved. I asked quite a few questions, and the person responding from the contest team did his best in helping me with the resources he could share, but still it took me quite a lot of time to understand the statement.
Note: This might not be the case for others, but it certainly is for me. And I know for a fact that a handful of us found the statement convoluting.
In the second test case how is (1,4,3), (1,4), (1,5) a possible path? If (1,4,3) is possible then why no (4,2) since we can reach 4 from 4 and 2 has lower rating than 4? Who wrote the statement first tell me? And who approved this?
one-way roads connecting them in such a way that they form an arborescence (a tree with all paths directed from the root), rooted at town 1.
As the roads are one way, and it’s an arborescence, there are no paths between 3 to 2. The edges are 1->3 and 1->2 . So we can’t go 3->1->2 . It’s a one-way road.
Anyway, the statement was confusing, and explanation of the test cases was no help too.
I understood it 1 hour after reading the problem. I was solving a whole different problem earlier.
Path 4 → 3 is not there. But 3 → 4 is there. According to the question, we can jump if there is a path between towns i and j, i.e. a path from town i to town j or from town j to town i.
So, the jump 4–>3 is a possible one.