@@ -45,7 +45,7 @@ values={[
45
45
``` java
46
46
// Network Delay Time
47
47
// Dijkstra
48
- // Time Complexity: O(logN*E ), Space Complexity: O(N + E)
48
+ // Time Complexity: O(ElogN ), Space Complexity: O(N + E)
49
49
class Solution {
50
50
public int networkDelayTime (int [][] times , int N , int K ) {
51
51
// adjacency list, map<vertex_id, map<vertex_id, weight>>
@@ -73,14 +73,14 @@ class Solution {
73
73
Map<Integer , Integer > father = new HashMap<> ();
74
74
75
75
// pair<distance, vertex_id>, min heap, sorted by distance from start to vertex_id
76
- Queue<int[]> pq = new PriorityQueue<> ((a, b) - > (a[ 0 ] - b[ 0 ] ));
76
+ Queue<Pair< Integer , Integer > > pq = new PriorityQueue<> ((a, b) - > a . getKey() - b. getKey( ));
77
77
78
78
// from start to start itself
79
- pq. offer(new int []{ 0 , start} );
79
+ pq. offer(new Pair ( 0 , start) );
80
80
dist. put(start, 0 );
81
81
82
82
while (! pq. isEmpty()){
83
- final int u = pq. poll()[ 1 ] ;
83
+ final int u = pq. poll(). getValue() ;
84
84
if (! graph. containsKey(u)) continue ; // leaf node
85
85
86
86
for (int v : graph. get(u). keySet()){
@@ -89,7 +89,7 @@ class Solution {
89
89
final int shorter = dist. get(u)+ w;
90
90
dist. put(v, shorter);
91
91
father. put(v, u);
92
- pq. offer(new int []{ shorter, v} );
92
+ pq. offer(new Pair ( shorter, v) );
93
93
}
94
94
}
95
95
}
@@ -108,3 +108,7 @@ class Solution {
108
108
109
109
</TabItem >
110
110
</Tabs >
111
+
112
+ ### 相关题目
113
+
114
+ - [ Path with Maximum Probability] ( path-with-maximum-probability.md )
0 commit comments