Railway Track

4

5 votes
Graphs, Minimum Spanning Tree, Algorithms, C++
Problem

Note: This is an approximate problem. There is no exact solution. You must find the most optimal solution. Please, take a look at the sample explanation to ensure that you understand the problem correctly.
 

Problem statement

Given a connected network G with N Railway Stations and M Railway Tracks. Each track connects two different Railway Stations and has a cost associated with it.

We have a set S consisting of Railway Stations in G. |S| = K .

We need to find a network T, which is a subnetwork of G and has all stations present in set S. (It is possible that T has some stations not present in S). In T ,  there must exists a unique path between any two stations.

We need to select T such that  (Z = Sum of costs of Tracks present in T) is minimized.  

Input format :

  • First line contains two space-separated integers : N and M
  • Next M lines contain three space separated integers U V W, denoting a track between station U and V with cost W.
  • Next line contain an integer K
  • Next line contain K space separated integers, denoting set S.

Output format :

  • In first line print E, number of edges in T
  • In next line print E space separated integers denoting the index of edges 1 - based (as per the Input) present in T.

Verdict and scoring :

  • Your score is equal to the sum of the values of all test files. The value of each test file is equal to the value of Z that you found.

    If T is invalid or T does not has all stations present in S then you will recieve a Wrong Answer Verdict.

Constraints :

  • N=100000,M=1000000
  • 5000<=K<=10000
  • 1<=W<=100000

 

Time Limit: 3
Memory Limit: 256
Source Limit:
Explanation

Edge Number : 4, 6. Covers all the vertices {2 , 3 , 5}

Z = 54 + 15 = 69

{Note: This is just a Sample Test, Test cases follow Input Constraints Mentioned}

Editor Image

?