Help with error

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

no not about time complexity , the cost may exceed the range of int if the constraints on the cost are high .
change int to long long and then try submitting.

if fails then try submiting it on other plaforms where constraints and input/output are clearly mentioned.

I don’t think that is the case because the cost is in the range of int


for example here but it is still not passing

if all test cases are like this then yeah thats is definetely not a reason still try submiting it using long long.

the logic for dijkastra is also correct(submit it over other platforms to verify).

the only thing that is left is input ,so the issue is probably with input that they have not expained clearly.

I wanted to know that why do we use set instead of pq( we were told updation is not possible in pq ) and how it effects the time complexity because I saw in other implementations online priority queue was being used .

yeah key updation is not possible in pq , wherease in set we can easily modify it in log(n) and it will also keep the keys in sorted order these were the reason why we are using set over pq.

yeah we can use pq as well, time complexity wise it will remain same.
refer this for better clarity->link

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.