#include <bits/stdc++.h>
using namespace std;
int i,node,sos,len,tg;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
vector<pair<int,int>> adj[N];
int dist[N][2];
int prov[N];
for(i = 0; i < N; i++){
dist[i][0]=2000000000;
dist[i][1]=2000000000;
prov[i]=N;
}
for(i = 0; i <K; i++){
dist[P[i]][1]=0;
dist[P[i]][0]=0;
}
for(i = 0; i < M; i++){
adj[R[i][1]].push_back({R[i][0],L[i]});
adj[R[i][0]].push_back({R[i][1],L[i]});
}
priority_queue<pair<int,int>> pq;
for(int i = 0; i < K; i++)pq.push({0,P[i]});
while(!pq.empty()){
node = pq.top().second;
sos = 0-pq.top().first;
pq.pop();
for(auto x: adj[node]){
len = x.second;
tg = x.first;
//cout << "len " << len << " tg " << tg << "\n";
if(dist[tg][0]>sos+len){
prov[tg]=node;
dist[tg][1]=dist[tg][0];
dist[tg][0]=sos+len;
pq.push({0-dist[tg][1],tg});
}else if(dist[tg][1]>sos+len && prov[tg]!=node){
dist[tg][1]=sos+len;
pq.push({0-dist[tg][1],tg});
}
}
}
return dist[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
416 KB |
Output is correct |
11 |
Correct |
1 ms |
512 KB |
Output is correct |
12 |
Correct |
5 ms |
768 KB |
Output is correct |
13 |
Correct |
4 ms |
896 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
656 ms |
56864 KB |
Output is correct |
17 |
Correct |
123 ms |
15348 KB |
Output is correct |
18 |
Correct |
149 ms |
16884 KB |
Output is correct |
19 |
Correct |
815 ms |
63720 KB |
Output is correct |
20 |
Correct |
379 ms |
47352 KB |
Output is correct |
21 |
Correct |
53 ms |
6520 KB |
Output is correct |
22 |
Correct |
432 ms |
45048 KB |
Output is correct |