For those of you who haven't solved this problem, this is one of the best problems from which you can learn how limitations of memory and time can make an easy problem, difficult to solve!
Just when I obtained the accepted sign after several trials, I was quite disappointed that I got a worst case running time of 1.98 s . So I headed over to Keshav's github repository and when I tried out the solution posted, it gave me a worst case running time of 0.024 s. Wow! Now that's a huge improvement. I really wanted to upgrade my arsenal with the procedure that had been used, but to my dismay I couldn't understand how it actually works. It would be great if someone posted the technique and procedure employed in solving the problem in the link attached above!
Problem in short: You are given a tree with N nodes, where each node i has a value v[i] associated with it. Find nodes i and j, such that i is an ancestor of j and (v[i] - v[j]) is maximized. N <= 10^5.
Indian National Olympiad in Informatics (INOI) is round 2 out of 3 (i.e. intermediate) for selection into Indian IOI team.
What is the best way to represent adjacency lists in C++98
INOI is coming up soon, and seeing that only C++98 was provided in ZCO, I won't be surprised (but would be upset) that they provide the same in INOI.
Normally I represent undirected graphs as an unordered_map of vectors, like this:
unordered_map <int, vector <int>> graph;
For directed graphs, I may use an unordered_map of unordered_maps to store the weights.
However, what is the best way to do so in C++98, especially for sparse graphs. Do I have to resort to something like: int graph[n][n] which would consume quite a lot of space, as it is basically just an adjacency matrix.
I need some help about what exactly should I do for inoi
My prob is i am confused about which dp topics to do and which to not. For example dp with bit masking is required or not. Also there were many many topics on geeks for geeks and i couldnt get which ones to do as time is limited. It is nowhere mentioned on iarcs etc. Which questions of dp go beyond inoi level? Also is there a need to do segment trees ( i have no idea about it).