Someone's Intermediate Representation



Here is the problem link.

This problem is all about BFS, but it really points out some of my weak points.

I almost cried in the library since this problem had bothered me for such a long time, I tried so hard, and I succeeded after all! Cheers!

Something about Algorithm

The problem’s main point is about BFS.

We can use the method to construct a distance map from 0 to the last talent, then construct two reverse talent maps from the talent to 0.

Finally we enumerate the sum of the 3 maps’ distances, find the smallest one, then we know the shortest path.