Comments

The test cases for F was weak.

For example, https://atcoder.jp/contests/abc142/submissions/9838374 This solution thinks that searching from any point must find the answer, but it is actually wrong.

case: 6 9 1 5 1 2 2 6 2 3 3 4 3 1 6 3 4 1 5 2

output: 5 1 5 2 6 3

answer: 3 1 2 3

Aha! I love problem F.

I solved this problem by randomization and binary search. The code is easy to read. 48318449

Let us analyze this problem, we know every truck must have the max gas-tanks. For a truck, the more oil, the better.

We randomly choose a truck to calculate ( use binary search ), It can be considered that in general, half of the trucks do not exceed the maximum fuel consumption. In other words, we only use logm operations( binary search) at most.

Another solution for the Problem E. Just brute force and greedy.

For every node (1 2 3 4) , we fix its matching priority. For example, node 1, match 2 first, then match 4, and then 3.

Why? If we choose three edges in our answer, for example, 1-2 , 1-3 , 1-2 . This means we can at least go back to node 1 twice. So why not choose the matching nodes in a fixed order ? (1-3, 1-2, 1-2) This means we must select node 3 before select node 2 when we are at node 1. This can be done for every nodes. And brute force matching priority only cost O((3!)^4) , the specific complexity depends on your implementation.

check my code for more details. 42952879

Sorry for my extremely poor English.

+1

You are right. But this solution can get Accepted. Emmm... Your test case is randomly generated data ? Maybe this solution based in some randomly theory?

+7

38770498

I can't understand this solution. Can someone explain this? Thanks.