My code is giving error.Its a one page error which i am unable to understand?
What is the error in my code?
#include<bits/stdc++.h>
using namespace std;
class Graph{
map<int,list<pair<int,int>>> m;
public:
void addEdge(int x,int y,int r){
m[x].push_back(make_pair(y,r));
m[y].push_back(make_pair(x,r));
}
void dijkstra(int src,int n){
map<int,int> dist;
set<pair<int,int>> s;
for(auto it:m){
dist[it.first]=INT_MAX;
}
dist[src]=0;
s.insert(dist[src],src);
while(!s.empty()){
auto p=*(s.begin());
int node=p.second;
int nodeDist=p.first;
s.erase(s.begin());
for(auto childPair:m[node]){
int child=childPair.first;
int childNodeDist=childPair.second;
if(nodeDist+childNodeDist<dist[child]){
auto f=s.find(make_pair(dist[child],child));
if(f!=s.end()){
s.erase(f);
}
dist[child]=nodeDist+childNodeDist;
s.insert(make_pair(dist[child],child));
}
}
}
for(int i=1;i<=n;i++){
if(i==src){
continue;
}
cout<<dist[i]<<" ";
}
}
};
int main(){
int t;
cin>>t;
while(t–){
int n,m;
cin>>n>>m;
Graph g;
for(int i=0;i<m;i++){
int x,y,r;
cin>>x>>y>>r;
g.addEdge(x,y,r);
}
int s;
cin>>s;
g.dijkstra(s,n);
}
}
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.