Optimal Control of a Discrete Time Stochastic Model of an Epidemic Spreading in Arbitrary Networks