Gardener and the Capybaras (hard version)

Problem Name:
Gardener and the Capybaras (hard version)
Site:CodeForces
Links:
Tags:
Problem setters: