graph algorithm go a step further.