please help me understand, how its input is working to get the given output.
Sir, i'm getting problem in the input and output data
hello @chandreshmaurya
did u read the input format ?
->
First line contains integer t as number of test cases.
Each test case contains following input.
First line contains three integers n, l, s which represents the number of cells of board, number of ladders and number of snakes.
Next l lines contains two integers each x & y denoting there is a ladder from x to y.
Next s lines contains two integers each x & y denoting there is a snake from x to y.
what is not clear in this?
for this " 30 4 4 3 22 5 8 11 26 20 29 17 4 19 7 21 9 27 1 " how is taking three steps to reach at the destination ?
manually it tough to find that path ,for that first u need to frame the board then ladders and then snakes
and then u need to manully find that path among all possible paths.
just assume the given output is true
ohhkay sir . .
sir, i solved, but i’m getting compilation error. please help me to correct my code -> https://ide.codingblocks.com/s/484465
what logic u r using ? how u will ensure that elements are traverersed in level order fashion ?
sir, i’m not using the level order traversal.
My logic-> First, I stored all ladder and snake combination in a ‘ladder’ and ‘snake’ map. After that, mai ek step me sare outcome try krta hu ( from 1 to 6). Then, mere pass do case aate hai, 1st-> mere ko ladder milegi, 2nd-> mere ko ladder nhi milegi. In 1st case-> abb phir se mere pass do case aate hain. In (1.1) -> jha pe mai ladder se phuchata(ladder_stop) hu whi pe snake ko aur mujhe kaat le to mai ‘snake stop’ pe aa jaunga. aur iss cheez ko m dusre map ‘m’ me store krta hu by m{snake_stop, start} . Now (1.2)-> isme jha pe mai by ladder phuchata hu wha pe koi snake nhi hai. the uss case ko mai m{ladder_stop,start} se store kra deta hu… Now, in 2nd case from point start hme koi ladder nhi milti, abb mai kisi ek point pe ( start+i) ke help se phuchata hu. isme bhi do cases hai. In (2.1) -> mai jha phuchata hu wha pe snake present ho aur mujhe kaat de and In (2.2) - > wha pe koi snake present nhi ho as i did in the (1.1 & 1.2 ) case. Abb mai while loop se bahar aata hu. then ‘count’ ko increment krta hu. and ’ map m ’ me jo maine store kraye hain as m({stop,start}) isme jo maxm stop hai use start se update krta hu. … then again while loop start to run until ’ start < n ’ … sir kya mera logic shi hai ?
…
yaha pe tum ye kaise keh sekta ho ki jo maximum stop hai wahi se tumhe shortest path milega?
aise bhi to ho sakta hai ki tumne koi smaller path choose kiya jo ki baad me kisi lambi letter se kaafi jaldi destination pe pahuch jaye.
is type ki problem ke liye bfs use kiya karo , kyunki usme har case consider karte hai bina kisi assumption ke to final path jo aayega wo shortest hoga ye guranteed hota hai
okay, I got my mistake. Now I’m going with the bfs.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.