I made a short editorial (not complete, i’ll complete it later). The contest was very nice (especially Chef and Gorden Ramsey) and this was my first long challenge.
Encoding can also be done by this approach :
If you are given a number N, calculate total plane sum from 0 to N and then calculate the loss (Ex : N = 1100 , loss = 100 because 1000 will be included) and then plane sum - loss will be the sum from 0 to N with given conditions. Now answer will be this sum for R - this sum for L-1.
Here is my solution : https://www.codechef.com/viewsolution/25870951
Take a node (let’s say 2). Add 2 to the indexed set.
Then, I will go through all of the unvisited neighbours of 2. Add them (node 1,3 and 4) to the indexed set and calculate* the number of answers for them. After this we can calculate* the number of answers for 2.
(*) We can see that we can calculate the number of solutions for a current node (taking it as the middle), knowing the number of nodes bigger than the current node and smaller than the current node.
My solution CodeChef: Practical coding for everyone
(functions : function isStar is for checking if the graph is a star and function star is to calculate the star case in O(n))