Codeforces and Polygon may be unavailable between Aug. 17, 19:00 (UTC) to Aug. 17, 22:00 (UTC) due to planned power outages. ×

Could you give more details for the O(mn) solution?
Oh, of course. Thank you! I've changed to an iterative function but it gives TL 28 now.

I'll try to code the good solution now.
A naive 15-line python code gives "runtime error on case 24" on problem D, but I expected something like TLE. What could be the reason for it? I usually code in C++ and I don't know what can cause a runtime error on python.

Thank you all!
I think each problemsetter sould write a sample solution in some common language and, of course, the tutorial.
dp(S), which has 2^n states, the cost of visiting all the vertices s_i in the set S.
Then, you can just visit one node, or two. This leads us to a n^2*2^n algorithm, which is too slow.

Coding it in n*2^n using the fact that you can start from the first element in the set should be enough. When you visit just one vertex do one recursive call, and when you have to visit a pair of vertices just iterate on the second one (you can choose s_1 always as the first one). Precalculating distances in an array may also be useful.
It also happened to me. It was path reconstruction.