Flocking while preserving connectivity