#include "bits/stdc++.h"
using namespace std;
#define ll long long
#define f first
#define s second
#define pi pair<ll,ll>
#define vi vector<ll>
#define vpi vector<pi>
#define pb push_back
#define INF 1000000000000
#define endl '\n'
//#define int ll
#define pii pair<pi,ll>
const int MAX = 1e5+1;
vpi g[MAX];
ll dis[MAX][2];
ll travel_plan(int n,int m, int R[][2], int L[],int k, int P[]){
ll a,b,c,from;
for(int i = 0; i < m; i++){
a = R[i][0];
b = R[i][1];
c = L[i];
g[a].pb({b,c});
g[b].pb({a,c});
}
priority_queue<pi, vector<pi>, greater<pi>>pq;
for(int i = 0; i < n; i++){
dis[i][0]=INF;
dis[i][1]=INF;
}
for(int i =0 ; i < k; i++){
dis[P[i]][0]=0;
dis[P[i]][1]=0;
pq.push({0,P[i]});
}
while(!pq.empty()){
b = pq.top().f;
from = pq.top().s;
pq.pop();
if(b!=dis[from][1]) {
continue;
}
for(pi i : g[from]){
int to = i.f;
int w= i.s;
if(dis[to][0]> b+w){
bool flag = false;
if(dis[to][0]!=INF ) flag = true;
dis[to][1] = dis[to][0];
dis[to][0] = b+w;
if(flag)pq.push({dis[to][1], to});
}
else if(dis[to][1]>b+w){
dis[to][1]=b+w;
pq.push({dis[to][1], to});
}
}
}
return dis[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
3 ms |
3420 KB |
Output is correct |
13 |
Correct |
3 ms |
3424 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2652 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2652 KB |
Output is correct |
4 |
Correct |
1 ms |
2908 KB |
Output is correct |
5 |
Correct |
2 ms |
2908 KB |
Output is correct |
6 |
Correct |
2 ms |
2652 KB |
Output is correct |
7 |
Correct |
2 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
9 |
Correct |
2 ms |
3164 KB |
Output is correct |
10 |
Correct |
1 ms |
2652 KB |
Output is correct |
11 |
Correct |
2 ms |
2908 KB |
Output is correct |
12 |
Correct |
3 ms |
3420 KB |
Output is correct |
13 |
Correct |
3 ms |
3424 KB |
Output is correct |
14 |
Correct |
2 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
272 ms |
66800 KB |
Output is correct |
17 |
Correct |
42 ms |
14420 KB |
Output is correct |
18 |
Correct |
54 ms |
16720 KB |
Output is correct |
19 |
Correct |
306 ms |
72948 KB |
Output is correct |
20 |
Correct |
178 ms |
55376 KB |
Output is correct |
21 |
Correct |
22 ms |
8280 KB |
Output is correct |
22 |
Incorrect |
196 ms |
49976 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |