package leetcode;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/shortest-path-with-alternating-colors/
 */
public class Problem1129 {
    public int[] shortestAlternatingPaths(int n, int[][] red_edges, int[][] blue_edges) {
        // TODO
        return null;
    }

    public static void main(String[] args) {
        Problem1129 prob = new Problem1129();
        System.out.println(Arrays.toString(prob.shortestAlternatingPaths(3,
            new int[][]{{0, 1}, {1, 2}}, new int[][]{}))); // [0,1,-1]
        System.out.println(Arrays.toString(prob.shortestAlternatingPaths(3,
            new int[][]{{0, 1}}, new int[][]{{2, 1}}))); // [0,1,-1]
        System.out.println(Arrays.toString(prob.shortestAlternatingPaths(3,
            new int[][]{{1, 0}}, new int[][]{{2, 1}}))); // [0,-1,-1]
        System.out.println(Arrays.toString(prob.shortestAlternatingPaths(3,
            new int[][]{{0, 1}}, new int[][]{{1, 2}}))); // [0,1,2]
        System.out.println(Arrays.toString(prob.shortestAlternatingPaths(3,
            new int[][]{{0, 1}, {0, 2}}, new int[][]{{1, 0}}))); // [0,1,1]
        System.out.println(Arrays.toString(prob.shortestAlternatingPaths(4,
            new int[][]{{0, 1}, {1, 2}, {3, 2}}, new int[][]{{1, 3}}))); // [0,1,3,2]
    }
}

@@ -36,16 +36,64 @@
 .Arrays;
+%0Aimport java.util.HashSet;%0Aimport java.util.Set;
 %0A%0A/**%0A *
@@ -295,35 +295,643 @@
     
-// TODO%0A        return null
+Set%3CInteger%3E%5B%5D redAdjList = buildGraph(n, red_edges);%0A        Set%3CInteger%3E%5B%5D blueAdjList = buildGraph(n, blue_edges);%0A        int%5B%5D answer = new int%5Bn%5D;%0A        return answer;%0A    %7D%0A%0A    private static Set%3CInteger%3E%5B%5D buildGraph(int n, int%5B%5D%5B%5D edges) %7B%0A        Set%3CInteger%3E%5B%5D graph = new Set%5Bn%5D;%0A        for (int i = 0; i %3C n; i++) %7B%0A            for (int%5B%5D edge : edges) %7B%0A                int from = edge%5B0%5D;%0A                int to = edge%5B1%5D;%0A                if (graph%5Bfrom%5D == null) %7B%0A                    graph%5Bfrom%5D = new HashSet%3C%3E();%0A                %7D%0A                graph%5Bfrom%5D.add(to);%0A            %7D%0A        %7D%0A        return graph
 ;%0A  
@@ -1022,24 +1022,26 @@
 blem1129();%0A
+//
         Syst
@@ -1096,32 +1096,34 @@
 rnatingPaths(3,%0A
+//
             new 
@@ -1169,32 +1169,34 @@
 )); // %5B0,1,-1%5D%0A
+//
         System.o
@@ -1247,32 +1247,34 @@
 rnatingPaths(3,%0A
+//
             new 
@@ -1322,24 +1322,26 @@
 // %5B0,1,-1%5D%0A
+//
         Syst
@@ -1396,32 +1396,34 @@
 rnatingPaths(3,%0A
+//
             new 
@@ -1476,16 +1476,18 @@
 ,-1,-1%5D%0A
+//
         
@@ -1546,32 +1546,34 @@
 rnatingPaths(3,%0A
+//
             new 
@@ -1620,24 +1620,26 @@
  // %5B0,1,2%5D%0A
+//
         Syst
@@ -1702,16 +1702,18 @@
 aths(3,%0A
+//
         

Update problem 1129