Given an undirected colored graph(edges are colored), with a source vertex ‘s’ and a destination vertex ‘d’, print number of paths which from given ‘s’ to ‘d’ such that the path is UniColored(edges in path having same color).
The edges are colored, here Colors are represented with numbers. At maximum, number of different colors will be number of edges.
Input : Graph u, v, color 1, 2, 1 1, 3, 2 2, 3, 3 2, 4, 2 2, 5, 4 3, 5, 3 4, 5, 2 source = 2 destination = 5 Output : 3 Explanation : There are three paths from 2 to 5 2 -> 5 with color red 2 -> 3 - > 5 with color sky blue 2 -> 4 - > 5 with color green
1. Do dfs traversal on the neighbour nodes of source node.
2. The color between source node and neighbour nodes is known, if the DFS traversal also have same color, proceed, else stop going on that path.
3. After reaching destination node, increment count by 1.
NOTE : Number of Colors will always be less than number of edges.
Number of unicolored paths : 3
Time Complexity : O(E * (E + V))
- Paths to travel each nodes using each edge (Seven Bridges of Königsberg)
- Print levels with odd number of nodes and even number of nodes
- Number of shortest paths in an unweighted and directed graph
- Number of unique paths in tree such that every path has a value greater than K
- Find maximum number of edge disjoint paths between two vertices
- Calculate number of nodes in all subtrees | Using DFS
- Count the number of non-reachable nodes
- Count the nodes whose sum with X is a Fibonacci number
- Number of special nodes in an n-ary tree
- Number of sink nodes in a graph
- Count the number of nodes at a given level in a tree using DFS
- Count the number of nodes at given level in a tree using BFS.
- Minimize the number of weakly connected nodes
- Level with maximum number of nodes using DFS in a N-ary tree
- Maximize number of nodes which are not part of any edge in a Graph
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : rituraj_jain