For San Francisco (and LA) use USA Hostels, by far the best run and most secure hostels I have ever stayed at. They are not the cheapest, and definitely need booking well ahead. Which attests to their popularity and reputation.
In Flagstaff I recommend the Grand Canyon International Hostel. This too I found, needs booking ahead in summer. The one time I did not book I had to stay at its sister hostel. I was most disappointed with its standard.
These hostels all organise regular community meals and tours at backpacker prices. The staff at each I found very knowledgable. (It is 5 - 7 years since I stayed at either.)
Lifey