I know that plain BFS search can be used for find shortest path in unweighted graph or graph with same edge weight, and Dijkstra should be used in weighted graph, and Dijkstra can be seen as a variant of BFS.
But I wonder if I push the node to the queue every time the dist[w] is updated, instead of only push once in plain BFS search, will this algorithm work for finding shortest path? I tried this algorithm on one leetcode problem, and it worked, but the leetcode problem only check limited testcase, so I cant prove the correctness of this algorithm. If the algorithm is correct, what's the time complexity?
vector<int>dist(N + 1, INT_MAX);
dist[start] = 0;
queue<int>q;
q.push(start);
while(!q.empty()){
int v = q.front(); q.pop();
for(auto [w, cost] : g[v]){
// cout<<w<<" "<<cost<<endl;
if(cost + dist[v] < dist[w]){
dist[w] = cost + dist[v];
q.push(w);
}
}
}