cses graph problem for labyrinth

Getting a TLE in test case 13 , on the labyrinth problem could anyone can help in this regard
My approach to the problem was to find shortest path using bfs it took me long enough to implement this please help in this regards
link: https://ideone.com/zaVKcB

Link is not working for me.

bro your link is not working

please check now

please check

Try long long
if it doesn’t work

try declaring global variables/containers in the function .

I tried didn’t worked

@vijju123 please help in this problem

if(x1-1==px){
        ans="D"+ans;
        x1=x1-1;
    }
    else if(x1+1==px){
         ans="U"+ans;
         x1=x1+1;
    }
    else if(y1-1==py) {
        ans="R"+ans;
        y1=y1-1;
    }
    else if(y1+1==py) {
        ans="L"+ans;
        y1=y1+1;
    }

Your implementation is pretty much inefficient.

You have another choice - rewrite it as
ans += "some_character", reverse the string at the end and print it.

Or you can print the characters one by one in the loop itself.

Thanks bro