package leetcode;

/**
 * https://leetcode.com/problems/time-needed-to-inform-all-employees/
 */
public class Problem1376 {
    public int numOfMinutes(int n, int headID, int[] manager, int[] informTime) {
        // TODO
        return 0;
    }

    public static void main(String[] args) {
        Problem1376 prob = new Problem1376();
        System.out.println(prob.numOfMinutes(1, 0, new int[]{-1}, new int[]{0})); // 0
        System.out.println(prob.numOfMinutes(6, 2, new int[]{2,2,-1,2,2,2}, new int[]{0,0,1,0,0,0})); // 1
        System.out.println(prob.numOfMinutes(7, 6, new int[]{1,2,3,4,5,6,-1}, new int[]{0,6,5,4,3,2,1})); // 21
        System.out.println(prob.numOfMinutes(15, 0, new int[]{-1,0,0,1,1,2,2,3,3,4,4,5,5,6,6}, new int[]{1,1,1,1,1,1,1,0,0,0,0,0,0,0,0})); // 3
        System.out.println(prob.numOfMinutes(4, 2, new int[]{3,3,-1,2}, new int[]{0,0,162,914})); // 1076
    }
}

@@ -12,16 +12,68 @@
 tcode;%0A%0A
+import java.util.ArrayList;%0Aimport java.util.List;%0A%0A
 /**%0A * h
@@ -263,687 +263,658 @@
     
-// TODO%0A        return 0
+List%3CInteger%3E%5B%5D graph = new List%5Bmanager.length%5D
 ;%0A    
-%7D%0A%0A
     
-public static void main(String%5B%5D args) %7B%0A        Problem1376 prob = new Problem1376();%0A        System.out.println(prob.numOfMinutes(1, 0, new int%5B%5D%7B-1%7D, new int%5B%5D%7B0%7D)); // 0%0A        System.out.println(prob.numOfMinutes(6, 2, new int%5B%5D%7B2,2,-1,2,2,2%7D, new int%5B%5D%7B0,0,1,0,0,0%7D)); // 1%0A        System.out.println(prob.numOfMinutes(7, 6, new int%5B%5D%7B1,2,3,4,5,6,-1%7D, new int%5B%5D%7B0,6,5,4,3,2,1%7D)); // 21%0A        System.out.println(prob.numOfMinutes(15, 0, new int%5B%5D%7B-1,0,0,1,1,2,2,3,3,4,4,5,5,6,6%7D, new int%5B%5D%7B1,1,1,1,1,1,1,0,0,0,0,0,0,0,0%7D)); // 3%0A        System.out.println(prob.numOfMinutes(4, 2, new int%5B%5D%7B3,3,-1,2%7D, new int%5B%5D%7B0,0,162,914%7D)); // 1076
+for (int i = 0; i %3C graph.length; i++) %7B%0A            graph%5Bi%5D = new ArrayList%3C%3E();%0A        %7D%0A        for (int i = 0; i %3C manager.length; i++) %7B%0A            if (manager%5Bi%5D != -1) %7B%0A                graph%5Bmanager%5Bi%5D%5D.add(i);%0A            %7D%0A        %7D%0A        return numOfMinutes(graph, informTime, headID);%0A    %7D%0A%0A    private static int numOfMinutes(List%3CInteger%3E%5B%5D graph, int%5B%5D informTime, int head) %7B%0A        int answer = 0;%0A        for (int child : graph%5Bhead%5D) %7B%0A            answer = Math.max(answer, numOfMinutes(graph, informTime, child) + informTime%5Bhead%5D);%0A        %7D%0A        return answer;
 %0A   

Solve problem 1376