Social Network (hard version)

Problem Name:
Social Network (hard version)
Site:CodeForces
Links:
Tags:
Problem setters: