I have come across a problem which goes something like this.
We are given an undirected graph where each edge has a value. Now the extra constraint is that one can not move from a higher value edge to a lower value edge. One always has to move from lower to higher value.
Pictorially the problem can be depicted as
1
1 / \ 1
/ \
3 7
2 / \ 3
/ \
4 5
So here we can move from 7 -> 1 -> 3 -> 4 but not 4 -> 3 -> 1. So in this graph we are asked to find out the strongly connected components like (1, 3, 7) in here.
I have tried to use Kosaraju's Algorithm with the constraint like this.
for v in adj[u]:
if not visited[v] and v.edgeValue >= u.edgeValue:
do work here
But the logic, I think, is wrong and I can not find out where it is failing. Can someone point out the fault and show some kind of pseudocode?
Thank you.