Hello Codeforces!
You are invited to participate in a New Year's contest hosted on DMOJ. The contest begins at Jan 4, 2pm UTC, and will be open for a 36-hour period. The contest will have 8 problems written by Eliden and myself, and you will be given 4 hours to solve them. For further details, please visit the contest page.
Happy new year, and good luck!
UPD:
The round is over. Congratulations to the winners:
Auto comment: topic has been updated by r3mark (previous revision, new revision, compare).
How to solve C?
Let dist(x) be the current distance from a1 to x. If adding the edge [ai, bi] reduces the value of dist(bi), we push the pair {dist(bi), ai} to the corresponding vector for bi. After doing this for i = 1, 2, ..., n, we can construct the answer by starting with bn and looking for the pair with first element dist(bn) in the vector for bn. The second element of this pair is the second to last node on the path. Letting this node equal p, we can continue by searching for the pair with first element dist(bn) - 1 in the vector corresponding to p, and so on.
Code