package leetcode;

/**
 * https://leetcode.com/problems/maximal-network-rank/
 */
public class Problem1615 {
    public int maximalNetworkRank(int n, int[][] roads) {
        // TODO
        return 0;
    }

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

@@ -12,16 +12,65 @@
 tcode;%0A%0A
+import java.util.HashSet;%0Aimport java.util.Set;%0A%0A
 /**%0A * h
@@ -221,32 +221,1020 @@
     
-// TODO%0A        return 0
+Set%3CString%3E%5B%5D graph = new Set%5Bn%5D;%0A        for (int%5B%5D road : roads) %7B%0A            if (graph%5Broad%5B0%5D%5D == null) %7B%0A                graph%5Broad%5B0%5D%5D = new HashSet%3C%3E();%0A            %7D%0A            String edge = edge(road%5B0%5D, road%5B1%5D);%0A            graph%5Broad%5B0%5D%5D.add(edge);%0A            if (graph%5Broad%5B1%5D%5D == null) %7B%0A                graph%5Broad%5B1%5D%5D = new HashSet%3C%3E();%0A            %7D%0A            graph%5Broad%5B1%5D%5D.add(edge);%0A        %7D%0A        int answer = 0;%0A        for (int i = 0; i %3C n; i++) %7B%0A            for (int j = i + 1; j %3C n; j++) %7B%0A                Set%3CString%3E set1 = graph%5Bi%5D != null ? graph%5Bi%5D : new HashSet%3C%3E();%0A                Set%3CString%3E set2 = graph%5Bj%5D != null ? graph%5Bj%5D : new HashSet%3C%3E();%0A                Set%3CString%3E set = new HashSet%3C%3E();%0A                set.addAll(set1);%0A                set.addAll(set2);%0A                answer = Math.max(answer, set.size());%0A            %7D%0A        %7D%0A        return answer;%0A    %7D%0A%0A    private static String edge(int a, int b) %7B%0A        return a %3C b ? a + %22,%22 + b : b + %22,%22 + a
 ;%0A  
@@ -1621,33 +1621,33 @@
 nk(%0A            
-4
+8
 , new int%5B%5D%5B%5D%7B%7B0
@@ -1685,20 +1685,410 @@
 7%7D%7D)); // 5%0A
+        System.out.println(prob.maximalNetworkRank(%0A            2, new int%5B%5D%5B%5D%7B%7D)); // 0%0A        System.out.println(prob.maximalNetworkRank(%0A            2, new int%5B%5D%5B%5D%7B%7B1, 0%7D%7D)); // 1%0A        System.out.println(prob.maximalNetworkRank(%0A            4, new int%5B%5D%5B%5D%7B%7B1, 0%7D, %7B2, 3%7D%7D)); // 2%0A        System.out.println(prob.maximalNetworkRank(%0A            3, new int%5B%5D%5B%5D%7B%7B0, 2%7D, %7B0, 1%7D%7D)); // 2%0A
     %7D%0A%7D%0A

Update problem 1615