Find a path from s to t using as few red nodes as possible The Next CEO of Stack OverflowDijkstra algorithm vs breadth first search for shortest path in graphAlgorithm to find diameter of a tree using BFS/DFS. Why does it work?Finding shortest path from a node to any node of a particular typeParallel algorithm to find if a set of nodes is on an elememtry cycle in a directed/undirected graphShortest path in unweighted graph using an iterator onlyShortest Path using DFS on weighted graphsCan a 3 Color DFS be used to identify cycles (not just detect them)?Find a path that contains specific nodes without back and forward edgesChecking if there is a single path that visits all nodes in a directed graphFind shortest path that goes through at least 5 red edges

Is it possible to make a 9x9 table fit within the default margins?

Compensation for working overtime on Saturdays

logical reads on global temp table, but not on session-level temp table

Early programmable calculators with RS-232

Incomplete cube

What does this strange code stamp on my passport mean?

Can I cast Thunderwave and be at the center of its bottom face, but not be affected by it?

It it possible to avoid kiwi.com's automatic online check-in and instead do it manually by yourself?

Why was Sir Cadogan fired?

Are British MPs missing the point, with these 'Indicative Votes'?

Could a dragon use its wings to swim?

My boss doesn't want me to have a side project

Does int main() need a declaration on C++?

Compilation of a 2d array and a 1d array

Can you teleport closer to a creature you are Frightened of?

Is a distribution that is normal, but highly skewed, considered Gaussian?

Variance of Monte Carlo integration with importance sampling

Which acid/base does a strong base/acid react when added to a buffer solution?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Calculating discount not working

How can the PCs determine if an item is a phylactery?

Strange use of "whether ... than ..." in official text

How to unfasten electrical subpanel attached with ramset

Man transported from Alternate World into ours by a Neutrino Detector



Find a path from s to t using as few red nodes as possible



The Next CEO of Stack OverflowDijkstra algorithm vs breadth first search for shortest path in graphAlgorithm to find diameter of a tree using BFS/DFS. Why does it work?Finding shortest path from a node to any node of a particular typeParallel algorithm to find if a set of nodes is on an elememtry cycle in a directed/undirected graphShortest path in unweighted graph using an iterator onlyShortest Path using DFS on weighted graphsCan a 3 Color DFS be used to identify cycles (not just detect them)?Find a path that contains specific nodes without back and forward edgesChecking if there is a single path that visits all nodes in a directed graphFind shortest path that goes through at least 5 red edges










3












$begingroup$


Was doing a little interview prep. Given an undirected graph G, such that each node is colored red or blue and |E|≥|V|, find a path in O(|E|) time such that starting and ending at 2 blue nodes, s and t, that you pass through as few red nodes as possible.



Initial Impressions: Since |E|≥|V|, O(|E|) time would include O(|E|+|V|), which means the solution likely uses BFS or DFS. Modifying the graph such that causing the all red nodes must be forced down a directed path of some long length (after making the whole graph directed) in order to use out-of-the-box BFS seems not viable, as it would mean constructing a new graph would be along O(|E||V|) time.



Another method I toyed around with was propagating values to nodes based on the safest path to that node while doing a DFS search, but not all values were guaranteed to update.



I still want to try to solve this myself, but I'm really stuck right now. Was wondering if there were any hints I could get. There are much simpler ways of doing this if it weren't for the O(|E|) time. Djikstras with creating some edge weights would work, but wouldn't be within the time bound.










share|cite|improve this question









$endgroup$







  • 1




    $begingroup$
    Try a variant of BFS in which you first find all red nodes reachable only via blue nodes, and so on.
    $endgroup$
    – Yuval Filmus
    4 hours ago















3












$begingroup$


Was doing a little interview prep. Given an undirected graph G, such that each node is colored red or blue and |E|≥|V|, find a path in O(|E|) time such that starting and ending at 2 blue nodes, s and t, that you pass through as few red nodes as possible.



Initial Impressions: Since |E|≥|V|, O(|E|) time would include O(|E|+|V|), which means the solution likely uses BFS or DFS. Modifying the graph such that causing the all red nodes must be forced down a directed path of some long length (after making the whole graph directed) in order to use out-of-the-box BFS seems not viable, as it would mean constructing a new graph would be along O(|E||V|) time.



Another method I toyed around with was propagating values to nodes based on the safest path to that node while doing a DFS search, but not all values were guaranteed to update.



I still want to try to solve this myself, but I'm really stuck right now. Was wondering if there were any hints I could get. There are much simpler ways of doing this if it weren't for the O(|E|) time. Djikstras with creating some edge weights would work, but wouldn't be within the time bound.










share|cite|improve this question









$endgroup$







  • 1




    $begingroup$
    Try a variant of BFS in which you first find all red nodes reachable only via blue nodes, and so on.
    $endgroup$
    – Yuval Filmus
    4 hours ago













3












3








3





$begingroup$


Was doing a little interview prep. Given an undirected graph G, such that each node is colored red or blue and |E|≥|V|, find a path in O(|E|) time such that starting and ending at 2 blue nodes, s and t, that you pass through as few red nodes as possible.



Initial Impressions: Since |E|≥|V|, O(|E|) time would include O(|E|+|V|), which means the solution likely uses BFS or DFS. Modifying the graph such that causing the all red nodes must be forced down a directed path of some long length (after making the whole graph directed) in order to use out-of-the-box BFS seems not viable, as it would mean constructing a new graph would be along O(|E||V|) time.



Another method I toyed around with was propagating values to nodes based on the safest path to that node while doing a DFS search, but not all values were guaranteed to update.



I still want to try to solve this myself, but I'm really stuck right now. Was wondering if there were any hints I could get. There are much simpler ways of doing this if it weren't for the O(|E|) time. Djikstras with creating some edge weights would work, but wouldn't be within the time bound.










share|cite|improve this question









$endgroup$




Was doing a little interview prep. Given an undirected graph G, such that each node is colored red or blue and |E|≥|V|, find a path in O(|E|) time such that starting and ending at 2 blue nodes, s and t, that you pass through as few red nodes as possible.



Initial Impressions: Since |E|≥|V|, O(|E|) time would include O(|E|+|V|), which means the solution likely uses BFS or DFS. Modifying the graph such that causing the all red nodes must be forced down a directed path of some long length (after making the whole graph directed) in order to use out-of-the-box BFS seems not viable, as it would mean constructing a new graph would be along O(|E||V|) time.



Another method I toyed around with was propagating values to nodes based on the safest path to that node while doing a DFS search, but not all values were guaranteed to update.



I still want to try to solve this myself, but I'm really stuck right now. Was wondering if there were any hints I could get. There are much simpler ways of doing this if it weren't for the O(|E|) time. Djikstras with creating some edge weights would work, but wouldn't be within the time bound.







graphs






share|cite|improve this question













share|cite|improve this question











share|cite|improve this question




share|cite|improve this question










asked 6 hours ago









Hunter DyerHunter Dyer

334




334







  • 1




    $begingroup$
    Try a variant of BFS in which you first find all red nodes reachable only via blue nodes, and so on.
    $endgroup$
    – Yuval Filmus
    4 hours ago












  • 1




    $begingroup$
    Try a variant of BFS in which you first find all red nodes reachable only via blue nodes, and so on.
    $endgroup$
    – Yuval Filmus
    4 hours ago







1




1




$begingroup$
Try a variant of BFS in which you first find all red nodes reachable only via blue nodes, and so on.
$endgroup$
– Yuval Filmus
4 hours ago




$begingroup$
Try a variant of BFS in which you first find all red nodes reachable only via blue nodes, and so on.
$endgroup$
– Yuval Filmus
4 hours ago










2 Answers
2






active

oldest

votes


















4












$begingroup$

To solve this, you need to use $BFS$. But first, manipulate $G$ so that the path will always favor blue vertices.



The solution has 2 parts:



  1. Use $DFS$ on blue vertices only, to find all all-blue strongly connected components, or $SCC$. Let's denote each $SCC$ by $v'$. Now, each blue $v in v'$ will be "compressed" to a single vertex $u$, and an edge $(u,x)$ will be added for every $x in N(v')$.
    Note any such $x$ is necessarily red.
    This step costs $O(V+E) = O(E)$, since $DFS$ is $O(V+E)$, and you have at most $V$ blue vertices, which make no more than $E$ new edges to add.

Step 1 means all paths that are blue-only will be free. On the new graph, the $BFS$ will only consider the edges which pass through a red vertex.



  1. Use $BFS$ from $s$. That length of the path to $t$ will essentially be the shortest path under the constraint of least red vertices in the path.





share|cite|improve this answer











$endgroup$












  • $begingroup$
    the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
    $endgroup$
    – Kevin Wang
    1 hour ago










  • $begingroup$
    I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
    $endgroup$
    – Apass.Jack
    54 mins ago


















1












$begingroup$

Convert $G$ to a directed graph $G'$ where we have two edges $(u,v)$ and $(v,u)$ in $G'$ for every edge $u,v$ in $G$. Let the length of $(u,v)$ be 1 if $v$ is a red node and 0 otherwise. Now run Dijkstra's algorithm on $G'$ from the starting node $s$ to the ending node $t$.





It is clear that the shortest path thus found passes as few red nodes as possible.



While we are running Dijkstra's algorithm, we are in one of two kinds of stages alternatively. One kind of stage is when we are exploring towards red nodes. The other kind of stage is when we are exploring towards blue nodes. Since each edge is checked/visited as most twice, the running time is $O(|E|)$.






share|cite|improve this answer











$endgroup$












  • $begingroup$
    Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
    $endgroup$
    – Hunter Dyer
    2 hours ago










  • $begingroup$
    I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
    $endgroup$
    – Apass.Jack
    1 hour ago











  • $begingroup$
    What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
    $endgroup$
    – Apass.Jack
    37 mins ago












Your Answer





StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
);
);
, "mathjax-editing");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "419"
;
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: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f106337%2ffind-a-path-from-s-to-t-using-as-few-red-nodes-as-possible%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









4












$begingroup$

To solve this, you need to use $BFS$. But first, manipulate $G$ so that the path will always favor blue vertices.



The solution has 2 parts:



  1. Use $DFS$ on blue vertices only, to find all all-blue strongly connected components, or $SCC$. Let's denote each $SCC$ by $v'$. Now, each blue $v in v'$ will be "compressed" to a single vertex $u$, and an edge $(u,x)$ will be added for every $x in N(v')$.
    Note any such $x$ is necessarily red.
    This step costs $O(V+E) = O(E)$, since $DFS$ is $O(V+E)$, and you have at most $V$ blue vertices, which make no more than $E$ new edges to add.

Step 1 means all paths that are blue-only will be free. On the new graph, the $BFS$ will only consider the edges which pass through a red vertex.



  1. Use $BFS$ from $s$. That length of the path to $t$ will essentially be the shortest path under the constraint of least red vertices in the path.





share|cite|improve this answer











$endgroup$












  • $begingroup$
    the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
    $endgroup$
    – Kevin Wang
    1 hour ago










  • $begingroup$
    I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
    $endgroup$
    – Apass.Jack
    54 mins ago















4












$begingroup$

To solve this, you need to use $BFS$. But first, manipulate $G$ so that the path will always favor blue vertices.



The solution has 2 parts:



  1. Use $DFS$ on blue vertices only, to find all all-blue strongly connected components, or $SCC$. Let's denote each $SCC$ by $v'$. Now, each blue $v in v'$ will be "compressed" to a single vertex $u$, and an edge $(u,x)$ will be added for every $x in N(v')$.
    Note any such $x$ is necessarily red.
    This step costs $O(V+E) = O(E)$, since $DFS$ is $O(V+E)$, and you have at most $V$ blue vertices, which make no more than $E$ new edges to add.

Step 1 means all paths that are blue-only will be free. On the new graph, the $BFS$ will only consider the edges which pass through a red vertex.



  1. Use $BFS$ from $s$. That length of the path to $t$ will essentially be the shortest path under the constraint of least red vertices in the path.





share|cite|improve this answer











$endgroup$












  • $begingroup$
    the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
    $endgroup$
    – Kevin Wang
    1 hour ago










  • $begingroup$
    I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
    $endgroup$
    – Apass.Jack
    54 mins ago













4












4








4





$begingroup$

To solve this, you need to use $BFS$. But first, manipulate $G$ so that the path will always favor blue vertices.



The solution has 2 parts:



  1. Use $DFS$ on blue vertices only, to find all all-blue strongly connected components, or $SCC$. Let's denote each $SCC$ by $v'$. Now, each blue $v in v'$ will be "compressed" to a single vertex $u$, and an edge $(u,x)$ will be added for every $x in N(v')$.
    Note any such $x$ is necessarily red.
    This step costs $O(V+E) = O(E)$, since $DFS$ is $O(V+E)$, and you have at most $V$ blue vertices, which make no more than $E$ new edges to add.

Step 1 means all paths that are blue-only will be free. On the new graph, the $BFS$ will only consider the edges which pass through a red vertex.



  1. Use $BFS$ from $s$. That length of the path to $t$ will essentially be the shortest path under the constraint of least red vertices in the path.





share|cite|improve this answer











$endgroup$



To solve this, you need to use $BFS$. But first, manipulate $G$ so that the path will always favor blue vertices.



The solution has 2 parts:



  1. Use $DFS$ on blue vertices only, to find all all-blue strongly connected components, or $SCC$. Let's denote each $SCC$ by $v'$. Now, each blue $v in v'$ will be "compressed" to a single vertex $u$, and an edge $(u,x)$ will be added for every $x in N(v')$.
    Note any such $x$ is necessarily red.
    This step costs $O(V+E) = O(E)$, since $DFS$ is $O(V+E)$, and you have at most $V$ blue vertices, which make no more than $E$ new edges to add.

Step 1 means all paths that are blue-only will be free. On the new graph, the $BFS$ will only consider the edges which pass through a red vertex.



  1. Use $BFS$ from $s$. That length of the path to $t$ will essentially be the shortest path under the constraint of least red vertices in the path.






share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited 1 hour ago









templatetypedef

5,59911945




5,59911945










answered 3 hours ago









loxlox

1866




1866











  • $begingroup$
    the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
    $endgroup$
    – Kevin Wang
    1 hour ago










  • $begingroup$
    I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
    $endgroup$
    – Apass.Jack
    54 mins ago
















  • $begingroup$
    the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
    $endgroup$
    – Kevin Wang
    1 hour ago










  • $begingroup$
    I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
    $endgroup$
    – Apass.Jack
    54 mins ago















$begingroup$
the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
$endgroup$
– Kevin Wang
1 hour ago




$begingroup$
the graph is undirected, so step 1 should be to find all all-blue connected components, not SCCs, right?
$endgroup$
– Kevin Wang
1 hour ago












$begingroup$
I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
$endgroup$
– Apass.Jack
54 mins ago




$begingroup$
I believe that is a typo by lox. Yes, it should be connected components instead of SCC.
$endgroup$
– Apass.Jack
54 mins ago











1












$begingroup$

Convert $G$ to a directed graph $G'$ where we have two edges $(u,v)$ and $(v,u)$ in $G'$ for every edge $u,v$ in $G$. Let the length of $(u,v)$ be 1 if $v$ is a red node and 0 otherwise. Now run Dijkstra's algorithm on $G'$ from the starting node $s$ to the ending node $t$.





It is clear that the shortest path thus found passes as few red nodes as possible.



While we are running Dijkstra's algorithm, we are in one of two kinds of stages alternatively. One kind of stage is when we are exploring towards red nodes. The other kind of stage is when we are exploring towards blue nodes. Since each edge is checked/visited as most twice, the running time is $O(|E|)$.






share|cite|improve this answer











$endgroup$












  • $begingroup$
    Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
    $endgroup$
    – Hunter Dyer
    2 hours ago










  • $begingroup$
    I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
    $endgroup$
    – Apass.Jack
    1 hour ago











  • $begingroup$
    What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
    $endgroup$
    – Apass.Jack
    37 mins ago
















1












$begingroup$

Convert $G$ to a directed graph $G'$ where we have two edges $(u,v)$ and $(v,u)$ in $G'$ for every edge $u,v$ in $G$. Let the length of $(u,v)$ be 1 if $v$ is a red node and 0 otherwise. Now run Dijkstra's algorithm on $G'$ from the starting node $s$ to the ending node $t$.





It is clear that the shortest path thus found passes as few red nodes as possible.



While we are running Dijkstra's algorithm, we are in one of two kinds of stages alternatively. One kind of stage is when we are exploring towards red nodes. The other kind of stage is when we are exploring towards blue nodes. Since each edge is checked/visited as most twice, the running time is $O(|E|)$.






share|cite|improve this answer











$endgroup$












  • $begingroup$
    Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
    $endgroup$
    – Hunter Dyer
    2 hours ago










  • $begingroup$
    I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
    $endgroup$
    – Apass.Jack
    1 hour ago











  • $begingroup$
    What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
    $endgroup$
    – Apass.Jack
    37 mins ago














1












1








1





$begingroup$

Convert $G$ to a directed graph $G'$ where we have two edges $(u,v)$ and $(v,u)$ in $G'$ for every edge $u,v$ in $G$. Let the length of $(u,v)$ be 1 if $v$ is a red node and 0 otherwise. Now run Dijkstra's algorithm on $G'$ from the starting node $s$ to the ending node $t$.





It is clear that the shortest path thus found passes as few red nodes as possible.



While we are running Dijkstra's algorithm, we are in one of two kinds of stages alternatively. One kind of stage is when we are exploring towards red nodes. The other kind of stage is when we are exploring towards blue nodes. Since each edge is checked/visited as most twice, the running time is $O(|E|)$.






share|cite|improve this answer











$endgroup$



Convert $G$ to a directed graph $G'$ where we have two edges $(u,v)$ and $(v,u)$ in $G'$ for every edge $u,v$ in $G$. Let the length of $(u,v)$ be 1 if $v$ is a red node and 0 otherwise. Now run Dijkstra's algorithm on $G'$ from the starting node $s$ to the ending node $t$.





It is clear that the shortest path thus found passes as few red nodes as possible.



While we are running Dijkstra's algorithm, we are in one of two kinds of stages alternatively. One kind of stage is when we are exploring towards red nodes. The other kind of stage is when we are exploring towards blue nodes. Since each edge is checked/visited as most twice, the running time is $O(|E|)$.







share|cite|improve this answer














share|cite|improve this answer



share|cite|improve this answer








edited 58 mins ago

























answered 2 hours ago









Apass.JackApass.Jack

13.7k1940




13.7k1940











  • $begingroup$
    Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
    $endgroup$
    – Hunter Dyer
    2 hours ago










  • $begingroup$
    I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
    $endgroup$
    – Apass.Jack
    1 hour ago











  • $begingroup$
    What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
    $endgroup$
    – Apass.Jack
    37 mins ago

















  • $begingroup$
    Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
    $endgroup$
    – Hunter Dyer
    2 hours ago










  • $begingroup$
    I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
    $endgroup$
    – Apass.Jack
    1 hour ago











  • $begingroup$
    What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
    $endgroup$
    – Apass.Jack
    37 mins ago
















$begingroup$
Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
$endgroup$
– Hunter Dyer
2 hours ago




$begingroup$
Yeah that definitely works, but the runtime of Dijkstra's is O(|E| + |V|log|V|) which is more than O(|E|).
$endgroup$
– Hunter Dyer
2 hours ago












$begingroup$
I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
$endgroup$
– Apass.Jack
1 hour ago





$begingroup$
I will show shortly that this particular run of Dijkstra's algorithm actually takes $O(|E|)$ time.
$endgroup$
– Apass.Jack
1 hour ago













$begingroup$
What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
$endgroup$
– Apass.Jack
37 mins ago





$begingroup$
What is nice about this simple kind of transformation is that it also works when we are dealing with a weighted graph. Just add a sufficiently large weight to edges that end with a red node. Also this algorithm seems significantly easier to code as well.
$endgroup$
– Apass.Jack
37 mins ago


















draft saved

draft discarded
















































Thanks for contributing an answer to Computer Science Stack Exchange!


  • 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.

Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcs.stackexchange.com%2fquestions%2f106337%2ffind-a-path-from-s-to-t-using-as-few-red-nodes-as-possible%23new-answer', 'question_page');

);

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







Popular posts from this blog

Invision Community Contents History See also References External links Navigation menuProprietaryinvisioncommunity.comIPS Community ForumsIPS Community Forumsthis blog entry"License Changes, IP.Board 3.4, and the Future""Interview -- Matt Mecham of Ibforums""CEO Invision Power Board, Matt Mecham Is a Liar, Thief!"IPB License Explanation 1.3, 1.3.1, 2.0, and 2.1ArchivedSecurity Fixes, Updates And Enhancements For IPB 1.3.1Archived"New Demo Accounts - Invision Power Services"the original"New Default Skin"the original"Invision Power Board 3.0.0 and Applications Released"the original"Archived copy"the original"Perpetual licenses being done away with""Release Notes - Invision Power Services""Introducing: IPS Community Suite 4!"Invision Community Release Notes

Canceling a color specificationRandomly assigning color to Graphics3D objects?Default color for Filling in Mathematica 9Coloring specific elements of sets with a prime modified order in an array plotHow to pick a color differing significantly from the colors already in a given color list?Detection of the text colorColor numbers based on their valueCan color schemes for use with ColorData include opacity specification?My dynamic color schemes

Tom Holland Mục lục Đầu đời và giáo dục | Sự nghiệp | Cuộc sống cá nhân | Phim tham gia | Giải thưởng và đề cử | Chú thích | Liên kết ngoài | Trình đơn chuyển hướngProfile“Person Details for Thomas Stanley Holland, "England and Wales Birth Registration Index, 1837-2008" — FamilySearch.org”"Meet Tom Holland... the 16-year-old star of The Impossible""Schoolboy actor Tom Holland finds himself in Oscar contention for role in tsunami drama"“Naomi Watts on the Prince William and Harry's reaction to her film about the late Princess Diana”lưu trữ"Holland and Pflueger Are West End's Two New 'Billy Elliots'""I'm so envious of my son, the movie star! British writer Dominic Holland's spent 20 years trying to crack Hollywood - but he's been beaten to it by a very unlikely rival"“Richard and Margaret Povey of Jersey, Channel Islands, UK: Information about Thomas Stanley Holland”"Tom Holland to play Billy Elliot""New Billy Elliot leaving the garage"Billy Elliot the Musical - Tom Holland - Billy"A Tale of four Billys: Tom Holland""The Feel Good Factor""Thames Christian College schoolboys join Myleene Klass for The Feelgood Factor""Government launches £600,000 arts bursaries pilot""BILLY's Chapman, Holland, Gardner & Jackson-Keen Visit Prime Minister""Elton John 'blown away' by Billy Elliot fifth birthday" (video with John's interview and fragments of Holland's performance)"First News interviews Arrietty's Tom Holland"“33rd Critics' Circle Film Awards winners”“National Board of Review Current Awards”Bản gốc"Ron Howard Whaling Tale 'In The Heart Of The Sea' Casts Tom Holland"“'Spider-Man' Finds Tom Holland to Star as New Web-Slinger”lưu trữ“Captain America: Civil War (2016)”“Film Review: ‘Captain America: Civil War’”lưu trữ“‘Captain America: Civil War’ review: Choose your own avenger”lưu trữ“The Lost City of Z reviews”“Sony Pictures and Marvel Studios Find Their 'Spider-Man' Star and Director”“‘Mary Magdalene’, ‘Current War’ & ‘Wind River’ Get 2017 Release Dates From Weinstein”“Lionsgate Unleashing Daisy Ridley & Tom Holland Starrer ‘Chaos Walking’ In Cannes”“PTA's 'Master' Leads Chicago Film Critics Nominations, UPDATED: Houston and Indiana Critics Nominations”“Nominaciones Goya 2013 Telecinco Cinema – ENG”“Jameson Empire Film Awards: Martin Freeman wins best actor for performance in The Hobbit”“34th Annual Young Artist Awards”Bản gốc“Teen Choice Awards 2016—Captain America: Civil War Leads Second Wave of Nominations”“BAFTA Film Award Nominations: ‘La La Land’ Leads Race”“Saturn Awards Nominations 2017: 'Rogue One,' 'Walking Dead' Lead”Tom HollandTom HollandTom HollandTom Hollandmedia.gettyimages.comWorldCat Identities300279794no20130442900000 0004 0355 42791085670554170004732cb16706349t(data)XX5557367