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
Output format
X (X<N) is the length of the path that you can find. The format of the output is as follows:
Constraints
2≤N≤10000, N−1≤M≤100000, 1≤K≤50001≤w≤1e5, 1≤u,v≤N, 1≤Bi≤N, 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: (1≤N≤1000, 1≤K≤500)
In 80% tests: (1≤N≤10000, 1≤K≤5000)
The input is randomly generated for each test file.
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