#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5+4;
const int INF = 1e9+2;
vector<pair<int,int>> adj[N];
int ds[N][2];
#define tp tuple<int,int,int>
signed travel_plan(signed n, signed m, signed r[][2], signed l[], signed k, signed p[]){
for (int i=0; i<m; i++){
adj[r[i][0]].push_back({r[i][1], l[i]});
adj[r[i][1]].push_back({r[i][0], l[i]});
}
for (int i=0; i<n; i++) ds[i][0]=INF, ds[i][1] = INF;
for (int i=0; i<k; i++) ds[p[i]][0]=0, ds[p[i]][1] = 0;
// <second best distance, best distance, node>
priority_queue<tp, vector<tp>, greater<tp>> q;
for (int i=0; i<k; i++) q.push({0,0,p[i]});
while (!q.empty()){
auto [b2,b1,u] = q.top(); q.pop();
if (b2 != ds[u][0] || b1 != ds[u][1]) continue;
for (auto [v,w]: adj[u]){
if (w + b2 < ds[v][1]){
ds[v][0] = ds[v][1]; ds[v][1] = w + b2;
q.push({ds[v][0], ds[v][1], v});
} else if (w + b2 < ds[v][0]){
ds[v][0] = w+b2;
q.push({ds[v][0], ds[v][1], v});
}
}
}
return ds[0][0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2812 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 ms |
2908 KB |
Output is correct |
8 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2812 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 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 |
2 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 |
2 ms |
3420 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
2648 KB |
Output is correct |
2 |
Correct |
1 ms |
2652 KB |
Output is correct |
3 |
Correct |
1 ms |
2648 KB |
Output is correct |
4 |
Correct |
2 ms |
2812 KB |
Output is correct |
5 |
Correct |
2 ms |
3160 KB |
Output is correct |
6 |
Correct |
1 ms |
2908 KB |
Output is correct |
7 |
Correct |
1 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 |
2 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 |
2 ms |
3420 KB |
Output is correct |
14 |
Correct |
1 ms |
2652 KB |
Output is correct |
15 |
Correct |
1 ms |
2908 KB |
Output is correct |
16 |
Correct |
234 ms |
87964 KB |
Output is correct |
17 |
Correct |
52 ms |
20936 KB |
Output is correct |
18 |
Correct |
64 ms |
23240 KB |
Output is correct |
19 |
Correct |
300 ms |
97464 KB |
Output is correct |
20 |
Correct |
153 ms |
69460 KB |
Output is correct |
21 |
Correct |
28 ms |
11864 KB |
Output is correct |
22 |
Correct |
185 ms |
66032 KB |
Output is correct |