Let's have a graph with this edge list:
edgelist =
{s -> 1, s -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 3 -> t, 4 -> 3, 4 -> t};
I want to know how to find all cycles with length>3 that must contain s or t or both
Let's have a graph with this edge list:
edgelist =
{s -> 1, s -> 2, 1 -> 3, 2 -> 1, 2 -> 4, 3 -> 2, 3 -> t, 4 -> 3, 4 -> t};
I want to know how to find all cycles with length>3 that must contain s or t or both
If those edges are directed, then you haven't got any cycles involving s or t. To specify undirected edges use \[UndirectedEdge], which shows up on SE as <->.
edgeList = {s <-> 1, s <-> 2, 1 <-> 3, 2 <-> 1, 2 <-> 4, 3 <-> 2, 3 <-> t, 4 <-> 3, 4 <-> t};
G = Graph[edgeList, VertexLabels -> "Name"];
tCycle = FindCycle[{G, t}, {4, Infinity}, All];
sCycle = FindCycle[{G, s}, {4, Infinity}, All];
Union[tCycle, sCycle]
Update
Nasi points out that the union contains the same edge list twice. Sorting each at levels 1 and 2 before taking the union will get rid of the duplicates.
tCycle = Map[Sort, tCycle, 2]
sCycle = Map[Sort, sCycle, 2]
Union[tCycle, sCycle]
Perhaps there is a clever SameTest option for Union that allows more flexibility.