Reading symbols from Solution...done.
[New LWP 51539]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Core was generated by `./Solution'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x0000000000401dc4 in solve[abi:cxx11](int, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >) (n=0, from=..., to=..., weigh=...)
at /usr/local/include/c++/8.3.0/bits/stl_iterator.h:966
966 operator-(const __normal_iterator<_Iterator, _Container>& __lhs,
To enable execution of this file add
add-auto-load-safe-path /usr/local/lib64/libstdc++.so.6.0.25-gdb.py
line to your configuration file "//.gdbinit".
To completely disable this security protection add
set auto-load safe-path /
line to your configuration file "//.gdbinit".
For more information about this security protection see the
"Auto-loading safe path" section in the GDB manual. E.g., run from the shell:
info "(gdb)Auto-loading safe path"
A node only has one parent (computational version of "parthenogenesis"!). So you should update that, not do a mass of deleting. When you finalise a node (by popping it off the priority queue) then you update the distance to any other node to which it has access. If one of those nodes needs its distance shortening then it is put in the priority queue.
You need to give us the input data that caused your crash. Also tell us what n and m actually mean. (m seems to be the number of weighted paths, but I don't know what n is.) Also, it's unclear whether this is a directed graph or not.
I need to find all paths from source to destination for a undirected weighted graph.
I have used Dijkstra algorithm here , in addition used list of parents to store all the shortest paths as you can see in the code here.
- You haven't provided the input that elicited your crash. It didn't crash for mine. But it didn't output anything meaningful either.
- You haven't told us what the individual inputs represent.
- You haven't told us how you expect your code to work. (Link to your algorithm or methodology).
If you don't answer questions fully and give all the information asked for then it is difficult to give assistance. Above all, we need an input file.
A priority queue is a perfectly good way of using Dijkstra's algorithm. It needs to be sorted on the basis of distance from source.
I would start by getting rid of the completely unnecessary splurge of headers.
while (!pq.empty()) {
const auto d = pq.top().first;
const auto o = pq.top().second;
pq.pop();
if (d > o->distance) {
continue;
}
for (const auto &pair : o->adjacent) {
const auto p = pair.first;
const auto e = pair.second;
if (p->distance > d + e) {
p->distance = d + e;
pq.push(make_pair(d + e, p));
}
}
}
bool first = true;
for (int j = 1; j <= n; j++) {
if (j == s) {
continue;
}
Here the last edge [C,B,7] is a re-definition (duplication) of previously defined edge [B,C,4]. Such duplication should results in logical input error.