If you have a graph represented as an adjacency list, how can you detect any odd length-ed
cycles in python?
Suppose you have a graph given as input:
A = {
1: [2, 4],
2: [1, 5],
3: [4, 5],
4: [1, 3, 5],
5: [2, 3, 4],
6: []
}
V = {
1: <node>,
2: <node>,
3: <node>,
4: <node>,
5: <node>,
6: <node>
}
A
is a dictionary where the key is a number and the value is a list of numbers, so there is an edge between the key to all of it's values. V
is a dictionary which maps a number to the node instance.
How can you detect if there is an odd length-ed cycle?
From the input above, there actually is one which uses nodes 3, 4, 5
.
Basically how can I get the output to be 3 4 5
?
Thanks