Baltic Olympiad in Informatics: 2002 Day 1, Problem 3
In the countryside a postman has to deliver post to customers that live in villages and along every road connecting the villages.
Your task is to help the postman design a route that goes through every village and every road at least once — the input data are such that this is always possible. However, each route also has a cost. The people in the villages wish that the postman visit their village as early as possible. Therefore, each village has made the following deal with the post: If the village
There are
Your task is to write a program that designs such a route that goes through each village and road at least once and maximizes the total profit (or minimizes the loss) of the post.
Constraints
Each village has access to an even number of road endings.
Input Specification
In the first line of input, there are two space-separated integers
In each of the following
In each of the following
Output Specification
Your program should write one positive integer
If there are several possible optimal routes, you may output any one of them.
Sample Input
6 7
1
7
4
10
20
5
2 4
1 5
2 1
4 5
3 6
1 6
1 3
Sample Output
7
1 5 4 2 1 6 3 1
Sample Explanation
The villages and roads are shown in the diagram above.
Village | |
---|---|
No interaction | |
No interaction |
The total profit from the table above is
Comments