I have a graph which looks like this：

`[(0,2),(1,2),(3,1)]`

Now I want to limit lengths of paths to 2 from node 2, such as this:

`[(0,2),(1,2)]`

So what’s the fastest method?

Limit lengths when doing what operation?

all_simple_paths has a cutoff parameter; set it to 2.

(I would not worry about whether it is “the fastest” method for most applications; generally the underlying implementations in igraph are well tuned.)

Limit lengths when doing what operation?

I want to find some nodes which have limited skips from start in my work codes，so I hope I can get a subgraph which longest path is 2 (or other pointed length)，is there a method to change a graph to the form which I want？if not，I will use all_simple_paths to complete this.

I do not understand what you are trying to do. A much clearer, and more detailed explanation would be needed before this can be answered. Include a concrete example.

If you are searching from a specific node (or a set of specific nodes one at a time) you can use igraph::ego, with order = 2, and also set mindist to eliminate the nodes 1 step away.

Imagine you have a map which contains many train stations and railways，and someone is asking you：“I want to go to stations which are five stations away from here，please give me these stations.”

This is what I want to do.

Dan’s suggestion of `ego()`

accomplishes that.