PLease help me in PRMSWAP

How can i approach this problem, i read solutions of other users too, but still not able to get the algorithm. Please help: