Print all nodes at distance k

Only two test cases is running.

@2018kucp1041
Read the question carefully. You’ve to print list of final nodes in sorted order. So instead of printing them direct, store them in some vector and just before printing it sort the elements. Doing this will pass all testcase. I have modified your code, here is the updated code

Done.
But still one test case is not running.

@2018kucp1041

  1. move line 146(v.clear()) at the end of while loop
    2)change line 147 to if(v.size()==0)
    If still getting wrong ans, take help from above modified code i have sent. It is working for all testcases.