diff --git a/Trajectories/trajectories.py b/Trajectories/trajectories.py
index 1233d8056d5dff9434a3f7d421d35f2c693dd0dc..d9ba1987d953d4be6708eeed7261a39dd48f3593 100755
--- a/Trajectories/trajectories.py
+++ b/Trajectories/trajectories.py
@@ -108,9 +108,13 @@ for n in topology.topological_sort(g):
                 if date_merging - date_splitting <= 6:
                     # We have a phantom pattern. Get the vertex on the
                     # side of the shortest path:
-                    v_short = topology.shortest_path(
-                        g, n1, n, weights = g.ep.cost_function,
-                        dag = True)[0][1]
+                    if g.ep.cost_function[(n1, pred[0])] \
+                       + g.ep.cost_function[(pred[0], n)] \
+                       < g.ep.cost_function[(n1, pred[1])] \
+                       + g.ep.cost_function[(pred[1], n)]:
+                        v_short = pred[0]
+                    else:
+                        v_short = pred[1]
 
                     if traj_prop[v_short] != traj_prop[n1]:
                         # Correct the trajectories that were assigned