Help with error

code: https://ide.codingblocks.com/s/444621

prob: implement djikstra’s algorithm

the answer is : [0, 7, 13, 27, 10, -1]
but it is giving wrong answer for one 1 value and not working correctly for other test cases

hello @raghav007

pls explain the input format of ur code.

	vector<vector<vector<int>>> edges =  {
	{
    
      {1, 7}
    },
    {
      {2, 6},
      {3, 20},
      {4, 3}
    },
    {
      {3, 14}
    }
    ,
    {
      {4, 2}
    }
    ,
    {},
    {}
  };

what u are doing here?

vector<vector<int> > edges ; is enough to store edges

adjacency list is given in vectors

can u please share the question link with me.

even adjacency list can be stored in

vector< vector<int> > adj;

they have solved it without using hashmap but it is not as simple as using hash map

yeah got the input format. they are using inner most vector for storing (vertex,cost) pair

yeah I converted the vectors into hashmap and used the code which was taught in class but there is something wrong

wait i m checking . . . . . . . . . . . . .

	for(auto i : distance){
		if(i.second == INT_MAX || ){
			ans.push_back(-1);
		}
		ans.push_back(i.second);
	}

this part is wrong , distance is unordered map it will give u keys in random order.

do this->

iterate from v = [0....last vertex]
          if distance.count(v)==0 or distance[v]==INT_MAX  // if key is not present then it means that particular vertex is not rechable
               push(-1)
          else
              push(distance[v])


this way?

check now->

also share the output of the given case, so that i can verify from my end

this is the required answer

@raghav007
check now->

10 is still missing and in other test cases there are a lot of differences

check the updated one,by mistake i shared older link ->

let me know what the verdict is…


it is only passing 2 of the test cases

pls share the problem constrains with me. . . . .

they have not stated the constraints and one of there solutions is having a time complexity of o(v^2 + e)
so probably that is not the reason, I think the issue is because I’m converting it into hashmap so it is not working properly