Блог пользователя sbereghici

Автор sbereghici, история, 9 лет назад, По-английски

I'm trying to solve a problem using Union Find, for storing Connected Components of a graph, and a Multiset for ordering the Components' Weights ... but i'm getting "SIGSECV ( Abort Called ) "... here is my code Link

  • Проголосовать: нравится
  • -16
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится

Line 18 should be Father[f1] = Father[f2];.

The reason you get a runtime error is as follows: Let's say f1 is different from a. Since you only change the parent pointer of a, the parent pointer of f1 still points to f1. However, the weight of f1 is removed from the multiset. So if you call the merge function again with f1, the program will try to erase Weight[f1] from the multiset. If the weight is no longer present though, Order.find(Weight[f1]) returns Order.end(), and calling erase on that produces a runtime error.

»
9 лет назад, # |
  Проголосовать: нравится +4 Проголосовать: не нравится