US supermarket chains Giant and Safeway have avoided a possible strike in the Baltimore-Washington area as workers voted to ratify a new four-year contract.