Descriptions:

Power Transmission (Hard Edition)

CodeForces - 1163C2