BFS | 99 % beats | Java
\n\n\n# Approach\n Describe your approach to solving the problem. \nApproach is very simple, Instead of using any Priorityqueue or any normal queue, we can simp
> ![today.png](https://assets.leetcode.com/users/images/c42423ea-a382-4886-a68a-5110b8e55da5_1724999991.8590295.png)\n\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nApproach is very simple, Instead of using any Priorityqueue or any normal queue, we can simply traverse through given edges and each time we can perform operation like virus spreading. That is, right from source vertex, at each iteration, it\'s neighbours `time` gets updates to the min possible time.\n\nAt the end when all the nodes are visited, we can return the Max value from them.\n\n\n# Code\n```java []\nclass Solution {\n    public int networkDelayTime(int[][] times, int n, int k) {\n        int result[] = new int[n + 1];\n        int int_max = Integer.MAX_VALUE;\n        Arrays.fill(result, int_max);\n        result[k] = 0;\n\n        for(int i = 0; i < n - 1; i++) {\n            boolean found = false;\n\n            for(int time[] : times) {\n                int src = time[0];\n                int dest = time[1];\n                int t = time[2];\n\n                if(result[src] == int_max) continue;\n                if(result[src] + t < result[dest]) {\n                    found = true;\n                    result[dest] = result[src] + t;\n                }\n            }\n            if(found == false) break;\n        }\n        int answer = -1;\n        for(int i = 1; i < n + 1; i++) {\n            if(result[i] == int_max) return -1;\n            answer = Math.max(answer, result[i]);\n        }\n        return answer;\n    }\n}\n```
['Java']