Skip to content

Commit 490beea

Browse files
Update and rename ShortestAlternatingPath.cpp to medium-1129-shortest_path_alternating_colors.cpp
1 parent e5d2652 commit 490beea

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

Codes/ShortestAlternatingPath.cpp renamed to Codes/medium-1129-shortest_path_alternating_colors.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,28 @@
1-
//implemented using Bellman's ford algo
1+
// You are given an integer n, the number of nodes in a directed graph where the nodes are labeled from 0 to n - 1.
2+
// Each edge is red or blue in this graph, and there could be self-edges and parallel edges.
3+
4+
// You are given two arrays redEdges and blueEdges where:
5+
6+
// redEdges[i] = [ai, bi] indicates that there is a directed red edge from node ai to node bi in the graph, and
7+
// blueEdges[j] = [uj, vj] indicates that there is a directed blue edge from node uj to node vj in the graph.
8+
9+
// Return an array answer of length n, where each answer[x] is the length of the shortest path from node 0 to node x such that
10+
// the edge colors alternate along the path, or -1 if such a path does not exist.
11+
12+
13+
14+
// Example 1:
15+
16+
// Input: n = 3, redEdges = [[0,1],[1,2]], blueEdges = []
17+
// Output: [0,1,-1]
18+
19+
// Example 2:
20+
21+
// Input: n = 3, redEdges = [[0,1]], blueEdges = [[2,1]]
22+
// Output: [0,1,-1]
23+
24+
25+
// implemented using Bellman's ford algo
226
class Solution {
327
public:
428
vector<int> shortestAlternatingPaths(int n, vector<vector<int>>& redEdges, vector<vector<int>>& blueEdges) {

0 commit comments

Comments
 (0)