B. Dreamoon and WiFi : CodeForces Help!

So, I am linking the Questiion HERE and its answer HERE .
Could someone explain what is the function doing actually ??
Thanks !!