Editorial for Baltic OI '01 P1 - Postman


Remember to use this editorial only when stuck, and not to copy-paste code from it. Please be respectful to the problem author and editorialist.
Submitting an official solution before solving the problem yourself is a bannable offence.

The graph presented in the task will always have an Euler cycle (all vertex degrees are even). An Euler cycle satisfies all conditions given in task.

The total profit does not depend on the chosen Euler cycle as shown below:

\displaystyle \text{Profit} = \sum_{i=1}^n (w(i)-k(i)) - m = \sum_{i=1}^n w(i) - \sum_{i=1}^n k(i) - m = \sum_{i=1}^n w(i) - \sum_{i=1}^n i - m

A tour which visits all edges and some more than once is always worse than an Euler cycle (because the postman is paid 1 euro for each road), thus the optimal solution is to simply return any Euler cycle.


Comments

There are no comments at the moment.