optimization problem using graph