This is a simple Dijkstra algorithm. Please tell me correct Time & Space complexities for this algorithm. Different articles on internet giving different answers. I am asking this for interview purpose
Also, let me know if this algorithm is correct or not.
int main ()
{
cin >> n >> m;
while (m--)
{
cin >> a >> b >> w;
v[a].push_back({b, w});
v[b].push_back({a, w});
}
priority_queue<int, vector<int>, greater<int>> q;
dist[1] = 0
q.push({1,0});
while (q.size() > 0)
{
auto curr = q.top();
q.pop();
int k = curr.first;
int currCost = curr.second;
for(auto it : grph[k])
{
child = it.first
w = it.second;
if ((currCost + w) < dist[child])
{
dist[child] = currCost + w;
q.push({dist[child], child});
}
}
}
cout << dist[n] << "\n";
}