Changed cost[a][b] to cost[b][a]