Optimal purification of thermal graph states