# select a subgraph with only paths that connects a source to a sink with at most N vertices

**URL:** https://igraph.discourse.group/t/select-a-subgraph-with-only-paths-that-connects-a-source-to-a-sink-with-at-most-n-vertices/1090
**Category:** Usage
**Tags:** Python
**Created:** [31 January 2022 17:19 UTC](https://igraph.discourse.group/t/select-a-subgraph-with-only-paths-that-connects-a-source-to-a-sink-with-at-most-n-vertices/1090 "2022-01-31T17:19:21Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![trekianov](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@trekianov](https://igraph.discourse.group/u/trekianov)
#### Post date: [31 January 2022 17:19 UTC](https://igraph.discourse.group/t/select-a-subgraph-with-only-paths-that-connects-a-source-to-a-sink-with-at-most-n-vertices/1090/1 "2022-01-31T17:19:21Z")

</div>

I have a source and a sink vertex and I would like to extract a subgraph from the original graph that is constituted by vertices that allow only paths between the source and the sink with at most N vertices. Do you think is it possible to define it properly with igraph functions?

---

<div class="post-metadata">

### Author: ![szhorvat](https://yyz2.discourse-cdn.com/free1/user_avatar/igraph.discourse.group/szhorvat/32/3_2.png) [@szhorvat](https://igraph.discourse.group/u/szhorvat)
#### Post date: [31 January 2022 17:34 UTC](https://igraph.discourse.group/t/select-a-subgraph-with-only-paths-that-connects-a-source-to-a-sink-with-at-most-n-vertices/1090/2 "2022-01-31T17:34:47Z")

</div>

It’s not quite clear to me what you mean, but this function may help:

[https://igraph.org/python/api/latest/igraph.Graph.html#get\_all\_simple\_paths](https://igraph.org/python/api/latest/igraph.Graph.html#get_all_simple_paths)

If it does not, please show a concrete example: (1) this is my input graph, with source and sink (2) this is the desired output.

---

<div class="post-metadata">

### Author: ![trekianov](https://avatars.discourse-cdn.com/v4/letter/t/90db22/32.png) [@trekianov](https://igraph.discourse.group/u/trekianov)
#### Post date: [31 January 2022 18:57 UTC](https://igraph.discourse.group/t/select-a-subgraph-with-only-paths-that-connects-a-source-to-a-sink-with-at-most-n-vertices/1090/3 "2022-01-31T18:57:21Z")

</div>

thanks for the link very useful, but I am not 100% sure that could be the complete answer.  
Here below an example of a graph in which I would like to have, for example, the subgraph that connects node 29 as source and 14 as sink but with at most 3 steps (29-27-24-14 for example). Therefore I would like to get rid in the subgraph of, for example 1 to 10 nodes and so on.  
 ![example](https://global.discourse-cdn.com/free1/uploads/igraph/original/1X/323303862476be818b8a38a53deb2fd6b9cc667d.png)
