The new traveling salesman problem

2.4

5 votes
Graphs, Algorithms, Graph Representation
Problem

There is a new version of the Traveling salesman problem

Alice entered a country that contains n cities and she wants to see all of the cities by incurring the the minimum cost possible. There are m two-way roads in the country. A road connects two cities and it has a cost. The ith road connects cities vi, ui and costs ci. The difference between this problem and the classic TSP problem is that switching from a road to another road has a cost.

The viscosity for each road is defined as the ith road has viscosity gi. Switching from a road with viscosity x to a road with viscosity y adds x2+y2 cost.
Find the minimum cost needed to see all of the cities.

Note

  • Alice is comfortable with seeing a city or a road several times.
  • This problem is an approximation problem and you will get a higher score if you print a path with a lower cost.


Input format

  • The first line contains two integers n, m.
  • The next m lines contain the description of roads where the ith line contains vi, ui, ci, and gi.

Output format

Print the order in which Alice will see the cities. In the first line, print k that denotes the number of roads in her path (n1k106). In the next line, print the numbers of the roads she will pass in order.

Constraints

3n,m1051ci,gi109

Country is connected

Sample Input
4 4
1 2 10 20
2 3 30 40
3 4 50 60
3 4 60 10
Sample Output
3
1 2 4
Time Limit: 5
Memory Limit: 256
Source Limit:
Explanation

The cost of the path is 10+202+402+30+402+102+60. While cost of the path [1, 2, 3] is 10+202+402+30+402+602+50.

 

Editor Image

?