Please follow https://www.irs.gov/newsroom/tips-for-parents-who-share-custody-or-alternate-tax-benefits.