Constraining cosmic rays and magnetic fields in the Perseus galaxy cluster with TeV observations by the MAGIC telescopes