Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

After rescuing the beautiful princess, Super Mario needs to find a way home - with the princess of course :-) He's very familiar with the

image text in transcribed

After rescuing the beautiful princess, Super Mario needs to find a way home - with the princess of course :-) He's very familiar with the 'Super Mario World', so he docsn't need a map, he only needs the best route in order to save time. There are A Villages and B Castles in the world. Villages are numbered 1A, and Castles are numbered A+1A+B. Mario lives in Village 1, and the castle he starts from is numbered A+B. Also, there are two-way roads connecting them. Two places are connected by at most one road and a place never has a road connecting to itself. Mario has already mensured the length of every road, but they don't want to walk all the time, siuce he walks one unit time for one unit distance (how slow!). Luckily, in the Castle where he saved the princess, Mario found a magic boot. If he wears it, he can super-run from one place to another IN NO TIME. (Don't worry about the princess, Mario has found a way to take her with him when super-running, but he wouldn't tell you :--P) Since there are traps in the Castles, Mario NEVER super-runs through a Castle. He always stops when there is a castle on the way. Also, he starts/stops super-runnings ONLY at Villages or Castles. Unfortunately, the magic boot is too old, so he cannot use it to cover more than L kilometers at a time, and he cannot use more than K times in total. When he comes back home, he can have it repaired and make it usable again. Input The first line in the input contains a single integer T, indicating the number of test cases (1T20). Each test case begins with five integers A,B,M,L and K - the number of Villages, the number of Castles ( 1A,B50), the number of roads, the maximal distance that can be covered at a time (1L500), and the number of times the boot can be used (0K10). The next M lines each contains three integers Xi,Yi,Li. That means there is a road connecting place Xi and Yi. The distance is Li, so the walk time is also Li(1Li100). Output For each test case in the input print a line containing a single integer indicating the minimal time needed to go home with the beautiful princess. It's guaranteed that Super Mario can always go home. Sample Input 1445432126655326110544391 Sample Output 9 algorithm will be design in c++

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions