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)
- Check if given path between two nodes of a graph represents a shortest paths
- Print levels with odd number of nodes and even number of nodes
- Number of unique paths in tree such that every path has a value greater than K
- Number of shortest paths in an unweighted and directed graph
- Find the number of paths of length K in a directed graph
- Find maximum number of edge disjoint paths between two vertices
- Number of special nodes in an n-ary tree
- Count the nodes whose sum with X is a Fibonacci number
- Calculate number of nodes in all subtrees | Using DFS
- Count the number of non-reachable nodes
- Number of sink nodes in a graph
- Level with maximum number of nodes using DFS in a N-ary tree
- Check which player visits more number of Nodes
- Minimize the number of weakly connected nodes
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