Neo4j-Cypher: Remove a node from a path and maintain the link to all nodes of the path
I want to remove one node from a path, without jeopardizing the original path nodes.
This is my test db:
I want to remove node (2) from the path, but I want nodes 1, 3, 4, and 5 to stay linked in the path.
Is there a way to do it in one query? So far I have the following:
MATCH p = (:Connect)-[:to*]-(:Connect)
WITH nodes(p) AS connectNodes
UNWIND connectNodes AS connectNode
WITH distinct connectNode
WHERE connectNode.connectID = 2
DETACH DELETE (connectNode)
This will remove node 2 and unlinkes the path
How can maintain the link between the nodes of the original path without node 2?
EDIT:
I solved it by modifying the accepted answer's response
//Make sure node (n) belongs to the path
MATCH (n:Connect cID:2)-[:to*]-(:Connect cID:5)
//get attached nodes, if any, ignoring directions
OPTIONAL MATCH (oa:connect)-[:to]-(n)-[:to]-(ob:connect)
//make sure nothing is duplicated
WHERE oa.cID <> ob.cID
//Use FOREACH to mimic if/else. Only merge oa to ob if they exist. Query fails without it
FOREACH (_ IN case when oa IS NOT NULL then [true] else end |
MERGE (oa)-[:to created: 1542103211]-(ob)
)
//Get n, and get all connected nodes to it, and delete the relationship(s)
WITH n
OPTIONAL MATCH (n)-[r:to]-(:Connect) DELETE r
neo4j path cypher graph-databases
add a comment |
I want to remove one node from a path, without jeopardizing the original path nodes.
This is my test db:
I want to remove node (2) from the path, but I want nodes 1, 3, 4, and 5 to stay linked in the path.
Is there a way to do it in one query? So far I have the following:
MATCH p = (:Connect)-[:to*]-(:Connect)
WITH nodes(p) AS connectNodes
UNWIND connectNodes AS connectNode
WITH distinct connectNode
WHERE connectNode.connectID = 2
DETACH DELETE (connectNode)
This will remove node 2 and unlinkes the path
How can maintain the link between the nodes of the original path without node 2?
EDIT:
I solved it by modifying the accepted answer's response
//Make sure node (n) belongs to the path
MATCH (n:Connect cID:2)-[:to*]-(:Connect cID:5)
//get attached nodes, if any, ignoring directions
OPTIONAL MATCH (oa:connect)-[:to]-(n)-[:to]-(ob:connect)
//make sure nothing is duplicated
WHERE oa.cID <> ob.cID
//Use FOREACH to mimic if/else. Only merge oa to ob if they exist. Query fails without it
FOREACH (_ IN case when oa IS NOT NULL then [true] else end |
MERGE (oa)-[:to created: 1542103211]-(ob)
)
//Get n, and get all connected nodes to it, and delete the relationship(s)
WITH n
OPTIONAL MATCH (n)-[r:to]-(:Connect) DELETE r
neo4j path cypher graph-databases
What should your preferred solution look like? Scenario I: 5->4->1 and 3->1, Scenario II: 5->4<-1 and 3->1 Scenario III: 5->4<-3 and 3->1 or Scenario IV: 5->4->3 and 3->1?
– ThirstForKnowledge
Nov 12 '18 at 14:41
@ThirstForKnowledge direction doesn't matter, as long as I can get all nodes of the path.
– Tarek Deeb
Nov 13 '18 at 7:33
add a comment |
I want to remove one node from a path, without jeopardizing the original path nodes.
This is my test db:
I want to remove node (2) from the path, but I want nodes 1, 3, 4, and 5 to stay linked in the path.
Is there a way to do it in one query? So far I have the following:
MATCH p = (:Connect)-[:to*]-(:Connect)
WITH nodes(p) AS connectNodes
UNWIND connectNodes AS connectNode
WITH distinct connectNode
WHERE connectNode.connectID = 2
DETACH DELETE (connectNode)
This will remove node 2 and unlinkes the path
How can maintain the link between the nodes of the original path without node 2?
EDIT:
I solved it by modifying the accepted answer's response
//Make sure node (n) belongs to the path
MATCH (n:Connect cID:2)-[:to*]-(:Connect cID:5)
//get attached nodes, if any, ignoring directions
OPTIONAL MATCH (oa:connect)-[:to]-(n)-[:to]-(ob:connect)
//make sure nothing is duplicated
WHERE oa.cID <> ob.cID
//Use FOREACH to mimic if/else. Only merge oa to ob if they exist. Query fails without it
FOREACH (_ IN case when oa IS NOT NULL then [true] else end |
MERGE (oa)-[:to created: 1542103211]-(ob)
)
//Get n, and get all connected nodes to it, and delete the relationship(s)
WITH n
OPTIONAL MATCH (n)-[r:to]-(:Connect) DELETE r
neo4j path cypher graph-databases
I want to remove one node from a path, without jeopardizing the original path nodes.
This is my test db:
I want to remove node (2) from the path, but I want nodes 1, 3, 4, and 5 to stay linked in the path.
Is there a way to do it in one query? So far I have the following:
MATCH p = (:Connect)-[:to*]-(:Connect)
WITH nodes(p) AS connectNodes
UNWIND connectNodes AS connectNode
WITH distinct connectNode
WHERE connectNode.connectID = 2
DETACH DELETE (connectNode)
This will remove node 2 and unlinkes the path
How can maintain the link between the nodes of the original path without node 2?
EDIT:
I solved it by modifying the accepted answer's response
//Make sure node (n) belongs to the path
MATCH (n:Connect cID:2)-[:to*]-(:Connect cID:5)
//get attached nodes, if any, ignoring directions
OPTIONAL MATCH (oa:connect)-[:to]-(n)-[:to]-(ob:connect)
//make sure nothing is duplicated
WHERE oa.cID <> ob.cID
//Use FOREACH to mimic if/else. Only merge oa to ob if they exist. Query fails without it
FOREACH (_ IN case when oa IS NOT NULL then [true] else end |
MERGE (oa)-[:to created: 1542103211]-(ob)
)
//Get n, and get all connected nodes to it, and delete the relationship(s)
WITH n
OPTIONAL MATCH (n)-[r:to]-(:Connect) DELETE r
neo4j path cypher graph-databases
neo4j path cypher graph-databases
edited Nov 13 '18 at 17:42
Tezra
5,05121042
5,05121042
asked Nov 12 '18 at 12:50
Tarek DeebTarek Deeb
1328
1328
What should your preferred solution look like? Scenario I: 5->4->1 and 3->1, Scenario II: 5->4<-1 and 3->1 Scenario III: 5->4<-3 and 3->1 or Scenario IV: 5->4->3 and 3->1?
– ThirstForKnowledge
Nov 12 '18 at 14:41
@ThirstForKnowledge direction doesn't matter, as long as I can get all nodes of the path.
– Tarek Deeb
Nov 13 '18 at 7:33
add a comment |
What should your preferred solution look like? Scenario I: 5->4->1 and 3->1, Scenario II: 5->4<-1 and 3->1 Scenario III: 5->4<-3 and 3->1 or Scenario IV: 5->4->3 and 3->1?
– ThirstForKnowledge
Nov 12 '18 at 14:41
@ThirstForKnowledge direction doesn't matter, as long as I can get all nodes of the path.
– Tarek Deeb
Nov 13 '18 at 7:33
What should your preferred solution look like? Scenario I: 5->4->1 and 3->1, Scenario II: 5->4<-1 and 3->1 Scenario III: 5->4<-3 and 3->1 or Scenario IV: 5->4->3 and 3->1?
– ThirstForKnowledge
Nov 12 '18 at 14:41
What should your preferred solution look like? Scenario I: 5->4->1 and 3->1, Scenario II: 5->4<-1 and 3->1 Scenario III: 5->4<-3 and 3->1 or Scenario IV: 5->4->3 and 3->1?
– ThirstForKnowledge
Nov 12 '18 at 14:41
@ThirstForKnowledge direction doesn't matter, as long as I can get all nodes of the path.
– Tarek Deeb
Nov 13 '18 at 7:33
@ThirstForKnowledge direction doesn't matter, as long as I can get all nodes of the path.
– Tarek Deeb
Nov 13 '18 at 7:33
add a comment |
2 Answers
2
active
oldest
votes
This is the simplest way to do it would be to match the paths that would be broken, and then create the new links in the same cypher that deletes the node.
// Match the target node for deletion
MATCH (nid:2)
// Match broken paths, if any
OPTIONAL MATCH (a)-[ra]->(n)-[rb]->(b)
// Create new link to replace destroyed ones
CREATE (a)-[r:to]->(b)
// Copy properties over, if any
SET r+=ra, r+=rb
// Remove target node
DETACH DELETE n
// If you want to keep the node and just disconnect it, replace last line with
// OPTIONAL MATCH (n)-[r:to]-() DELETE r
There are APOC functions you can use to create a relation with a dynamic type if you want to copy the type from one of the removed relationships.
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete withOPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
|
show 2 more comments
An additional opportunity would be the removal of node "2" and the usage of the APOC procedure "Redirect relationship to". You can find a detailed description and illustrating images in the procedure documentation.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262563%2fneo4j-cypher-remove-a-node-from-a-path-and-maintain-the-link-to-all-nodes-of-th%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
This is the simplest way to do it would be to match the paths that would be broken, and then create the new links in the same cypher that deletes the node.
// Match the target node for deletion
MATCH (nid:2)
// Match broken paths, if any
OPTIONAL MATCH (a)-[ra]->(n)-[rb]->(b)
// Create new link to replace destroyed ones
CREATE (a)-[r:to]->(b)
// Copy properties over, if any
SET r+=ra, r+=rb
// Remove target node
DETACH DELETE n
// If you want to keep the node and just disconnect it, replace last line with
// OPTIONAL MATCH (n)-[r:to]-() DELETE r
There are APOC functions you can use to create a relation with a dynamic type if you want to copy the type from one of the removed relationships.
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete withOPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
|
show 2 more comments
This is the simplest way to do it would be to match the paths that would be broken, and then create the new links in the same cypher that deletes the node.
// Match the target node for deletion
MATCH (nid:2)
// Match broken paths, if any
OPTIONAL MATCH (a)-[ra]->(n)-[rb]->(b)
// Create new link to replace destroyed ones
CREATE (a)-[r:to]->(b)
// Copy properties over, if any
SET r+=ra, r+=rb
// Remove target node
DETACH DELETE n
// If you want to keep the node and just disconnect it, replace last line with
// OPTIONAL MATCH (n)-[r:to]-() DELETE r
There are APOC functions you can use to create a relation with a dynamic type if you want to copy the type from one of the removed relationships.
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete withOPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
|
show 2 more comments
This is the simplest way to do it would be to match the paths that would be broken, and then create the new links in the same cypher that deletes the node.
// Match the target node for deletion
MATCH (nid:2)
// Match broken paths, if any
OPTIONAL MATCH (a)-[ra]->(n)-[rb]->(b)
// Create new link to replace destroyed ones
CREATE (a)-[r:to]->(b)
// Copy properties over, if any
SET r+=ra, r+=rb
// Remove target node
DETACH DELETE n
// If you want to keep the node and just disconnect it, replace last line with
// OPTIONAL MATCH (n)-[r:to]-() DELETE r
There are APOC functions you can use to create a relation with a dynamic type if you want to copy the type from one of the removed relationships.
This is the simplest way to do it would be to match the paths that would be broken, and then create the new links in the same cypher that deletes the node.
// Match the target node for deletion
MATCH (nid:2)
// Match broken paths, if any
OPTIONAL MATCH (a)-[ra]->(n)-[rb]->(b)
// Create new link to replace destroyed ones
CREATE (a)-[r:to]->(b)
// Copy properties over, if any
SET r+=ra, r+=rb
// Remove target node
DETACH DELETE n
// If you want to keep the node and just disconnect it, replace last line with
// OPTIONAL MATCH (n)-[r:to]-() DELETE r
There are APOC functions you can use to create a relation with a dynamic type if you want to copy the type from one of the removed relationships.
edited Nov 13 '18 at 17:04
answered Nov 12 '18 at 15:23
TezraTezra
5,05121042
5,05121042
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete withOPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
|
show 2 more comments
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete withOPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
after modifying this query, it worked (please see the edited OP). But it fails on edge nodes. It only works on nodes that are connected to more than 1 node. In my original graph, it fails on 1, 3, and 5. How can I make it dynamic enough to work on any node?
– Tarek Deeb
Nov 13 '18 at 16:31
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete with
OPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
@TarekDeeb detach delete was suppose to clean up the edges, if you want to keep the node, and just remove it from all graphs, you can replace detach delete with
OPTIONAL MATCH (n)-[r:to]-() DELETE r
– Tezra
Nov 13 '18 at 16:51
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
This will just remove the relationship. I need to maintain the link to the original path. So if I have (1)-(2)-(3) and remove (2), your solution works, and I'll get (1)-(3). But If I want to remove (3), I want to still be left with (1)-(2). The removed node will not be deleted, but only not belonging to the original path.
– Tarek Deeb
Nov 13 '18 at 16:55
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
@TarekDeeb With the replace I gave you, (1)-(2)-(3) target 3 will result in (1)-(2) and (3), I don't understand what else you want to happen (your description sounds like that is what you wanted)
– Tezra
Nov 13 '18 at 17:02
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
I'm sorry I just saw your edit in your response. I modified the query to work on both cases and all is well. Check the modified query in my OP. Many thanks for your help!
– Tarek Deeb
Nov 13 '18 at 17:19
|
show 2 more comments
An additional opportunity would be the removal of node "2" and the usage of the APOC procedure "Redirect relationship to". You can find a detailed description and illustrating images in the procedure documentation.
add a comment |
An additional opportunity would be the removal of node "2" and the usage of the APOC procedure "Redirect relationship to". You can find a detailed description and illustrating images in the procedure documentation.
add a comment |
An additional opportunity would be the removal of node "2" and the usage of the APOC procedure "Redirect relationship to". You can find a detailed description and illustrating images in the procedure documentation.
An additional opportunity would be the removal of node "2" and the usage of the APOC procedure "Redirect relationship to". You can find a detailed description and illustrating images in the procedure documentation.
answered Nov 13 '18 at 21:11
ThirstForKnowledgeThirstForKnowledge
6551112
6551112
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53262563%2fneo4j-cypher-remove-a-node-from-a-path-and-maintain-the-link-to-all-nodes-of-th%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What should your preferred solution look like? Scenario I: 5->4->1 and 3->1, Scenario II: 5->4<-1 and 3->1 Scenario III: 5->4<-3 and 3->1 or Scenario IV: 5->4->3 and 3->1?
– ThirstForKnowledge
Nov 12 '18 at 14:41
@ThirstForKnowledge direction doesn't matter, as long as I can get all nodes of the path.
– Tarek Deeb
Nov 13 '18 at 7:33