Get your taxes done using TurboTax

If the kids lived with the grandparents for more than 1/2 the year then they get to claim the kids  since the kids did not live with you for more than 1/2 the year.  Legal custody is immaterial ... the IRS goes off physical custody.