0% found this document useful (0 votes)
154 views4 pages

Shortest Path Problems: Baba Yaga-Mission

John needs to calculate the shortest path from source to destination for his missions while avoiding areas under repair. Given a graph with nodes representing locations and edges representing routes between them, the assistant finds the shortest path from Mouchak to Dhaka University that avoids nodes marked as yellow, which are under repair. The output path is Mouchak->Shahbagh->TSC->BUET->Dhaka University with a total cost of 22 markers.

Uploaded by

Savage cgpian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
154 views4 pages

Shortest Path Problems: Baba Yaga-Mission

John needs to calculate the shortest path from source to destination for his missions while avoiding areas under repair. Given a graph with nodes representing locations and edges representing routes between them, the assistant finds the shortest path from Mouchak to Dhaka University that avoids nodes marked as yellow, which are under repair. The output path is Mouchak->Shahbagh->TSC->BUET->Dhaka University with a total cost of 22 markers.

Uploaded by

Savage cgpian
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Shortest Path Problems

1.Baba Yaga-mission: Your very close friend, John, also known as the Baba Yaga,
is often on various missions to complete different tasks. For this, he needs to travel
to different countries. For each of his missions, he has a peculiar ritual. Let‟s say, he
is going from country s to country t. He will start his journey from s, visit Continental
Hotel, located at country x, and then go to country t. Even if the country t falls on his
path from s to x, he will first go to x and then return to t. Consider this as a
professional courtesy. To travel from one country to another, he needs to spend a
few markers for different favors like mission equipment, food, travel cost, etc. A
marker is a small round metal object indicating a debt between two individuals.
Markers are witnessed and recognized. That means, if one person offers a marker to
another and asks for a favor, the offered person must comply. It is evident from
previous statements that these markers are very precious. For this reason, John
wants to minimize the number of markers used.

John knows that you‟re a great programmer. So he has asked you to calculate the
number of markers he requires to go on his missions.

For each case, print the case number first. Then for all the missions, you have to
print the number of markers required in a newline. If such required path from
country s to country t doesn‟t exist, print “Be seeing ya, John” (without the quotation
marks).

Sample Input

The first line of each test case contains 4 integers, N , the number of countries, M ,
the number of flights connecting them, x (1 ≤ x ≤ N), the location of Continental Hotel
and Q, the number of missions John needs to participate in. The countries are
conveniently numbered from 1 to N.The next M lines each will contain three
integers u, v and w (1 ≤ u, v ≤ N) indicating that there is a flight from u to v which
costs w markers. Then the following Q lines each will contain two integers s (1 ≤ s ≤
N), the country where John currently is in, and t (1 ≤ t ≤ N), the country he needs to
go to. There can be multiple flights between two countries.

4 4 3 2
1 2 4
1 3 20
2 3 4
3 4 4
1 4 //source(s)-1 & destination (t)-4
2 4 //source(s)-2 & destination (t)-4

Sample Output

Case 1:
12
8

For the first query, John will go through the following sequence of countries: 1 -> 2 -> 3 -> 4. The num
ber of markers required: (4 + 4 + 4) = 12.

2.Baba Yaga in Dhaka: John has decided to come to Dhaka for an assassination.
He has heard from his associates from Bangladesh that repair work is going on in
some areas of Dhaka city, such as-Rampura, Lalmatia etc. He wanted one of you
from BRAC University to determine the shortest path from „Mouchak‟ to „DU‟-which
path will avoid all the areas which are under maintenance work. You will be given the
source node,s and destination node,t in the two lines before last line of input file.
Last line contains the list of Yellow nodes‟ number. Yellow nodes are going through
construction work. Use a greedy approach to solve it and make sure to avoid some
nodes while considering the nodes to be visited. The full name of each area and their
node no in input file is given below in the following table- -

Node Location
M,0 Mouchak
Pn ,1 Panthapath
Dh ,4 Dhanmondi
Lm ,5 Lalmatia
R ,2 Rampura
B ,6 Badda
H ,7 Hatirjheel
Sh ,3 Shahahbagh
N ,8 Nilkhet
TSC,9 TSC
DU, 10 Dhaka University
BUET ,11 BUET

Yellow Repairing
White OK

Sample Input

12 //no. of nodes

16 //no. of connecting routes

0,1,5

0,2,2

0,3,10

1,4,20

1,5,10

2,6,3

2,7,12

3,8,5

3,9,8

4,11,5

5,10,6
7,8,2

8,10,10

8,11,12

9,11,2

11,10,2

0 //source-Mouchak

10 //destination-DU

2,5,6,8 //colour-yellow

Sample Ouput

Mouchak->Shahbagh->TSC->BUET->Dhaka University

Path cost: 22

You might also like