c++ dijkstra with priority queue
\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n        // build graph \n        vector<vector<pair<int, int>
```\nclass Solution {\npublic:\n    int networkDelayTime(vector<vector<int>>& times, int N, int K) {\n        // build graph \n        vector<vector<pair<int, int> > > graph(N+1);\n        for (auto edge : times) {\n            int fr_node = edge[0];\n            int to_node = edge[1];\n            int cost = edge[2];\n            graph[fr_node].push_back(make_pair(cost, to_node));            \n        }\n        vector<int> dist(N+1, INT_MAX);\n        priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>> pq;\n        dist[K] = 0;\n        pq.push(make_pair(0, K));        \n        while (!pq.empty()) {\n            pair<int,int> x = pq.top();\n            pq.pop();\n            for (auto neighbor : graph[x.second]) {\n                int ar = dist[x.second] + neighbor.first;\n                if (ar < dist[neighbor.second]) {\n                    dist[neighbor.second] = ar;\n                    pq.push(make_pair(ar, neighbor.second));\n                }\n            }            \n        }        \n        int max_time = INT_MIN;\n        for (int i = 1; i < dist.size(); ++i) {\n            if (max_time < dist[i]) {\n                max_time = dist[i];\n            }\n        }\n        \n        return max_time == INT_MAX? -1 : max_time;\n    }\n};\n```
['C', 'Heap (Priority Queue)']