Shortest cycle in a graph

#include<bits/stdc++.h>
using namespace std;
class graph
{
public:
map<int,list > l;
map<int,int> dis;
void addedge(int x,int y)
{
l[x].push_back(y);
l[y].push_back(x);
}
void shortest_cycle(int src,int& ans)
{
for(auto x:l)
dis.insert({x.first,INT_MAX});
queue q;
q.push(src);
dis[src] = 0;
while(!q.empty())
{
int cur = q.front();
q.pop();
for(auto nbr:l[cur])
{
if(dis[nbr] == INT_MAX)
{
dis[nbr] = dis[cur] + 1;
q.push(nbr);
}
else if(dis[nbr] >= dis[cur])
{
ans = min(ans,dis[nbr]+dis[cur]+1);
}
}
}
}
};
int main()
{
graph g;
g.addedge(1,2);
g.addedge(1,3);
g.addedge(2,4);
g.addedge(2,5);
g.addedge(4,5);
g.addedge(5,3);
int ans = INT_MAX;
for(auto p : g.l)
{
g.shortest_cycle(p.first,ans);
}
cout<<“shortest cycle is “<<ans<<”\n”;
}

@Amarjeet-Chaudhary-2033361970298469
what is the problem there is a hint video for the same.
also share your code using cb ide as it is very diff to look at it like this
(Also sry for the late reply)

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.