In order to avoid duplicates you would need only first level nodes:
categories.Where(n => n.ParentId == 0)
categories.Where(n => n.ParentId == 0)