| 28 | } |
| 29 | //time complexity! |
| 30 | public int networkDelayTime(int[][] times, int n, int k) { |
| 31 | ArrayList<ArrayList<int[]>> adj = new ArrayList<>(); |
| 32 | for(int i=0;i<n;i++){ |
| 33 | adj.add(new ArrayList<>()); |
| 34 | } |
| 35 | for(int time[] : times){ |
| 36 | int u = time[0]-1; |
| 37 | int v = time[1]-1; |
| 38 | int w = time[2]; |
| 39 | adj.get(u).add(new int[]{v,w}); |
| 40 | } |
| 41 | int minTime[] = dijkstra(k-1,n, adj); |
| 42 | int res = Integer.MIN_VALUE; |
| 43 | for(int time : minTime){ |
| 44 | res = Math.max(res,time); |
| 45 | } |
| 46 | return (res==Integer.MAX_VALUE)?-1:res; |
| 47 | } |
| 48 | } |