@@ -0,0 +1,1369 @@
+package leetcode;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Arrays;%0Aimport java.util.List;%0A%0A/**%0A * https://leetcode.com/problems/find-if-path-exists-in-graph/%0A */%0Apublic class Problem1971 %7B%0A    public boolean validPath(int n, int%5B%5D%5B%5D edges, int start, int end) %7B%0A        List%3CInteger%3E%5B%5D adjList = new List%5Bn%5D;%0A        for (int%5B%5D edge : edges) %7B%0A            if (adjList%5Bedge%5B0%5D%5D == null) %7B%0A                adjList%5Bedge%5B0%5D%5D = new ArrayList%3C%3E();%0A            %7D%0A            adjList%5Bedge%5B0%5D%5D.add(edge%5B1%5D);%0A            if (adjList%5Bedge%5B1%5D%5D == null) %7B%0A                adjList%5Bedge%5B1%5D%5D = new ArrayList%3C%3E();%0A            %7D%0A            adjList%5Bedge%5B1%5D%5D.add(edge%5B0%5D);%0A        %7D%0A        int number = 0;%0A        int%5B%5D groups = new int%5Bn%5D;%0A        Arrays.fill(groups, -1);%0A        for (int i = 0; i %3C n; i++) %7B%0A            if (groups%5Bi%5D != -1) %7B%0A                continue;%0A            %7D%0A            traverse(adjList, groups, number++, i);%0A        %7D%0A        return groups%5Bstart%5D == groups%5Bend%5D;%0A    %7D%0A%0A    private static void traverse(List%3CInteger%3E%5B%5D adjList, int%5B%5D groups, int number, int node) %7B%0A        groups%5Bnode%5D = number;%0A        if (adjList%5Bnode%5D == null) %7B%0A            return;%0A        %7D%0A        for (int adj : adjList%5Bnode%5D) %7B%0A            if (groups%5Badj%5D != -1) %7B%0A                continue;%0A            %7D%0A            traverse(adjList, groups, number, adj);%0A        %7D%0A    %7D%0A%7D%0A

Solve problem 1971