#include<bits/stdc++.h>
using namespace std ;
#define pii pair<int,int>
const int mx = 1e5 + 5 , inf = 1e9 + 10 ;
vector<pii> adj[mx] ;
int dist[mx] , vis[mx] , ans[mx][2] ;
int push_down(int a , int d)
{
if(d<=ans[a][0])
{
ans[a][1] = ans[a][0] ;
ans[a][0] = d ;
dist[a] = ans[a][1] ;
return 1 ;
}
if(d<ans[a][1])
{
ans[a][1] = dist[a] = d ;
return 1 ;
}
return 0 ;
}
void djikstra(int n , int m , int r[][2] , int l[] , int k , int p[])
{
for(int i = 0 ; i < n ; ++i) dist[i] = ans[i][0] = ans[i][1] = inf ;
priority_queue<pii,vector<pii>,greater<pii> > pq ;
for(int i = 0 ; i < k ; ++i)
{
pq.push({0,p[i]}) ;
dist[p[i]] = ans[p[i]][0] = ans[p[i]][1] = 0 ;
}
while(!pq.empty())
{
pii pr = pq.top() ;
pq.pop() ;
int to = pr.second ;
if(vis[to]) continue ;
vis[to] = 1 ;
int siz = adj[to].size() ;
for(int i = 0 ; i < siz ; ++i)
{
pr = adj[to][i] ;
int a = pr.first , b = pr.second ;
int d = dist[to] + b ;
if(push_down(a,d)) pq.push({ans[a][1],a}) ;
}
}
}
int travel_plan(int n , int m , int r[][2] , int l[] , int k , int p[])
{
for(int i = 0 ; i < m ; ++i)
{
int a = r[i][0] , b = r[i][1] ;
adj[a].push_back({b,l[i]}) ;
adj[b].push_back({a,l[i]}) ;
}
djikstra(n,m,r,l,k,p) ;
return ans[0][1] ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2680 KB |
Output is correct |
3 |
Correct |
7 ms |
2680 KB |
Output is correct |
4 |
Correct |
7 ms |
2808 KB |
Output is correct |
5 |
Correct |
8 ms |
2808 KB |
Output is correct |
6 |
Correct |
8 ms |
2808 KB |
Output is correct |
7 |
Correct |
7 ms |
2808 KB |
Output is correct |
8 |
Correct |
7 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2680 KB |
Output is correct |
3 |
Correct |
7 ms |
2680 KB |
Output is correct |
4 |
Correct |
7 ms |
2808 KB |
Output is correct |
5 |
Correct |
8 ms |
2808 KB |
Output is correct |
6 |
Correct |
8 ms |
2808 KB |
Output is correct |
7 |
Correct |
7 ms |
2808 KB |
Output is correct |
8 |
Correct |
7 ms |
2808 KB |
Output is correct |
9 |
Correct |
10 ms |
2936 KB |
Output is correct |
10 |
Correct |
7 ms |
2680 KB |
Output is correct |
11 |
Correct |
7 ms |
2808 KB |
Output is correct |
12 |
Correct |
10 ms |
3192 KB |
Output is correct |
13 |
Correct |
10 ms |
3192 KB |
Output is correct |
14 |
Correct |
7 ms |
2808 KB |
Output is correct |
15 |
Correct |
7 ms |
2808 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
2680 KB |
Output is correct |
2 |
Correct |
6 ms |
2680 KB |
Output is correct |
3 |
Correct |
7 ms |
2680 KB |
Output is correct |
4 |
Correct |
7 ms |
2808 KB |
Output is correct |
5 |
Correct |
8 ms |
2808 KB |
Output is correct |
6 |
Correct |
8 ms |
2808 KB |
Output is correct |
7 |
Correct |
7 ms |
2808 KB |
Output is correct |
8 |
Correct |
7 ms |
2808 KB |
Output is correct |
9 |
Correct |
10 ms |
2936 KB |
Output is correct |
10 |
Correct |
7 ms |
2680 KB |
Output is correct |
11 |
Correct |
7 ms |
2808 KB |
Output is correct |
12 |
Correct |
10 ms |
3192 KB |
Output is correct |
13 |
Correct |
10 ms |
3192 KB |
Output is correct |
14 |
Correct |
7 ms |
2808 KB |
Output is correct |
15 |
Correct |
7 ms |
2808 KB |
Output is correct |
16 |
Correct |
591 ms |
58600 KB |
Output is correct |
17 |
Correct |
118 ms |
15608 KB |
Output is correct |
18 |
Correct |
151 ms |
17140 KB |
Output is correct |
19 |
Correct |
740 ms |
63960 KB |
Output is correct |
20 |
Correct |
374 ms |
49656 KB |
Output is correct |
21 |
Correct |
56 ms |
8312 KB |
Output is correct |
22 |
Correct |
407 ms |
46712 KB |
Output is correct |