Skip to content

Commit 31bea1a

Browse files
committed
Runtime: 220 ms (Top 41.81%) | Memory: 44.6 MB (Top 18.95%)
1 parent 7c1f040 commit 31bea1a

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

scripts/algorithms/N/Network Delay Time/Network Delay Time.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// Runtime: 220 ms (Top 41.81%) | Memory: 44.6 MB (Top 18.95%)
12
class cmp{
23
public:
34
bool operator()(pair<int,int> &a,pair<int,int> &b)
@@ -14,23 +15,23 @@ class Solution {
1415
{
1516
a[it[0]-1].push_back({it[1]-1,it[2]});
1617
}
17-
18+
1819
priority_queue<pair<int,int>,vector<pair<int,int>>,cmp> pq;
1920
vector<int> dist(n,1e7);
20-
21+
2122
pq.push({k-1,0});
22-
23+
2324
vector<int> vis(n,0);
2425
while(pq.size())
2526
{
2627
auto curr = pq.top();
2728
pq.pop();
28-
29+
2930
int v = curr.first;
3031
int w = curr.second;
31-
32+
3233
if(vis[v])continue;
33-
34+
3435
vis[v] = 1;
3536
dist[v] = w;
3637
for(auto it:a[v])
@@ -41,13 +42,13 @@ class Solution {
4142
}
4243
}
4344
}
44-
45+
4546
int mx = INT_MIN;
4647
for(auto it:dist)
4748
mx = max(mx,it);
48-
49+
4950
if(mx>=1e7)return -1;
5051
return mx;
51-
52+
5253
}
53-
};
54+
};

0 commit comments

Comments
 (0)