If cigarettes and alcohol are do dangerous, why are they legal?

Excellent question. Probably because they have a longer history of use and are more socially acceptable. But both tobacco and alcohol cause a tremendous amount of disease and are by no means safe.
Use and lobbies. These are traditional products, available long before heath and other risks have reached the public forum. They exist in the market because they are addictive and have a huge following, they are agricultural products with a significant lobby, they are a tremendous source of tax revenue and history shows that attempts to eliminate them have only made the problem worse - e.g. Prohibition.