Optimal time-varying topology for network systems