package leetcode;

/**
 * https://leetcode.com/problems/redundant-connection/
 */
public class Problem684 {
    public int[] findRedundantConnection(int[][] edges) {
        // TODO
        return new int[0];
    }

    public static void main(String[] args) {
        Problem684 prob = new Problem684();
        System.out.println(prob.findRedundantConnection(new int[][]{
            {1, 2}, {1, 3}, {2, 3}
        })); // [2,3]
        System.out.println(prob.findRedundantConnection(new int[][]{
            {1,2}, {2,3}, {3,4}, {1,4}, {1,5}
        })); // [1,4]
    }
}

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashMap;%0Aimport java.util.Map;%0A%0A
 /**%0A * h
@@ -258,16 +258,773 @@
 %0A    %7D%0A%0A
+    private static class UnionFind %7B%0A        private final Map%3CInteger, Integer%3E map = new HashMap%3C%3E();%0A%0A        public void union(int a, int b) %7B%0A            if (!map.containsKey(a)) %7B%0A                map.put(a, a);%0A            %7D%0A            if (!map.containsKey(b)) %7B%0A                map.put(b, b);%0A            %7D%0A            while (!connected(a, b)) %7B%0A                int value = map.get(a);%0A                for (Map.Entry%3CInteger, Integer%3E e : map.entrySet()) %7B%0A                    if (e.getValue().equals(value)) %7B%0A                        map.put(e.getKey(), map.get(b));%0A                    %7D%0A                %7D%0A            %7D%0A        %7D%0A%0A        public boolean connected(int a, int b) %7B%0A            return map.get(a).equals(map.get(b));%0A        %7D%0A    %7D%0A%0A
     publ

Update problem 684