Dijkstra's Algorithm, but it's shortest time instead of shortest distance.
IntuitionBasically using Dijsktra's algorithm but instead of distance and weight, its just using time.ApproachUse exact ditto-copy paste of dijsktra algorithm..
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
Basically using Dijsktra's algorithm but instead of distance and weight, its just using time.
# Approach
<!-- Describe your approach to solving the problem. -->
Use exact ditto-copy paste of dijsktra algorithm... But,
the distance we usually calculate, consider it to be now time to be calculated.
Make sure to convert it from 1-based index to 0-based index, by simply subtracting the nodes with -1. it is given in the code when i add the adjaceny list.
Add the first node to the PriorityQueue, that is the k node, as per the question.
then extract it from the queue, store it in the variable, so that you can take it's adjacent nodes (as shown in the for loop from the adjaceny list)
now take the nodes from teh adjaceny list, of the adjacent node 
that is adj.get(node) -> the node's adjacent-node.
then basically just check that if the time you you have now, and the time it already took for the first node, is smaller than the current one... here is where the dijsktra algo is taken place.
In Dijkstra, we check for shortest distance, similarly, we see the shortest time taken.
so update it to the visitedtime array, and add the new nodes (that is the adjacent-node of the current node which you took from the queue.)
then it will be repeated
the rest just check if any of the elment is infinite, retun -1 else add the total time 
and thats it, you solved it!

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(N + E) becuase its graph quesiton lol

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(N) visited time extra space.

# Code
```java []
import java.util.*;

class Tuple {
    int first, second;

    public Tuple(int first, int second) {
        this.first = first;
        this.second = second;
    }
}

class Solution {
    public int networkDelayTime(int[][] times, int n, int k) {
        List<List<Tuple>> adj = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            adj.add(new ArrayList<>());
        }

        // Convert 1-based indexing to 0-based indexing
        for (int[] time : times) {
            adj.get(time[0] - 1).add(new Tuple(time[1] - 1, time[2]));
        }

        // Priority queue for Dijkstra’s algorithm
        PriorityQueue<Tuple> q = new PriorityQueue<>(Comparator.comparingInt(a -> a.second));

        // Distance array, initialized with infinity (MAX_VALUE)
        int[] visitedtime = new int[n];
        Arrays.fill(visitedtime, Integer.MAX_VALUE);
        visitedtime[k - 1] = 0;  // Convert source node `k` to 0-based

        q.add(new Tuple(k - 1, 0));

        while (!q.isEmpty()) {
            Tuple it = q.poll();
            int node = it.first;
            int t = it.second;

            for (Tuple iter : adj.get(node)) {
                int adjnode = iter.first;
                int edgetime = iter.second;

                if (t + edgetime < visitedtime[adjnode]) {
                    visitedtime[adjnode] = t + edgetime;
                    q.add(new Tuple(adjnode, visitedtime[adjnode]));
                }
            }
        }

        // Find the maximum time taken to reach any node
        int maxTime = 0;
        for (int time : visitedtime) {
            if (time == Integer.MAX_VALUE) {
                return -1;  // Some nodes are unreachable
            }
            maxTime = Math.max(maxTime, time);
        }

        return maxTime;
    }
}

```
['Breadth-First Search', 'Graph', 'Heap (Priority Queue)', 'Shortest Path', 'Java']