adding graph with matrix implementation