Passing intermediate cities

4.3

3 votes
Graphs, Priority queue, Algorithms, C++, Shortest Path Algorithms
Problem

Note: This is an approximate problem. No exact solution exists for this question. You must find the most optimal solution. Refer to the sample explanation to ensure that you understand the problem correctly.
 

Problem statement

You are given a weighted connected graph G with N vertices and M edges. There are no self-loops and multiple edges between two vertices in G. You are given two vertices u and v (u!=v). Here, u is the Source and v is the Destination. Also, you are given a set of K vertices B1, B2, ..., Bk (no vertex is equal to u and v). Your task is to find a path between source and destination such that value of Z is minimized.

Z=Weight of path×Y.

where Y is equal to the count of the vertex on a path that does not belong to a set of K vertices.

Input format

  • The first line contains three space-separated integers N M K.
  • The next line contains two integers u and v denoting the source and destination vertex.
  • Each of the next M lines contains 3 space-separated integers u v w denoting edge between vertex u and v (u!=v) with weight w (1e5).
  • The next line contains K space-separated integers denoting the vertices B1, B2, ..., Bk.

Output format

X (X<N) is the length of the path that you can find. The format of the output is as follows:

  • In the first line, print X denoting the length of the path (number of edges in the path)
  • In each of the X lines, print the edge numbers (position of the edge in the Input) in a sequential form.
    For example 
    If the path found is a1, a2, a3, ..., ap, then print X=P1 (length of the path), Source = a1, and Destination = ap.
    Edge number for edge connecting a1 a2
    Edge number for edge connecting a2 a3
    Edge number for edge connecting a3 a4
    ...............
    Edge number for edge connecting ap1 ap

Constraints

2N10000, N1M100000, 1K50001w1e5, 1u,vN, 1BiN, All Bi are distinct

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 can find.

If the path is invalid, then you receive Wrong Answer Verdict.

Test generation plan

In 20% tests: (1N1000, 1K500

In 80% tests: (1N10000, 1K5000

The input is randomly generated for each test file.

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

K = 2 , vertices in set are 3 4.

Selected Path is 1 - 2 - 4 - 5.

Weight of Path = 2 + 23 + 1 = 26
Y = 3 ( vertex 4 is present in set of K vertex)

Z = 26*3 = 78

Editor Image

?