#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MX = 1e5 + 5, inf = 1e18;
ll dist[MX][2];
int N, M, K;
vector<pair<int, int>> g[MX];
int travel_plan(int _N, int _M, int r[][2], int l[], int _K, int p[]) {
N = _N, M = _M, K = _K;
for(int i = 0; i < MX; i++) {
dist[i][0] = dist[i][1] = inf;
}
for(int i = 0; i < M; i++) {
g[r[i][0]].push_back({r[i][1], l[i]});
g[r[i][1]].push_back({r[i][0], l[i]});
}
priority_queue<pair<ll,ll>> pq;
for(int i = 0; i < K; i++) {
dist[p[i]][0] = dist[p[i]][1] = 0;
for(auto [u, w] : g[p[i]]) {
pq.push({-w, u});
}
}
while(!pq.empty()) {
auto [d, v] = pq.top(); pq.pop();
d = -d;
if(d < dist[v][0]) {
dist[v][0] = d;
} else if(d < dist[v][1]) {
dist[v][1] = d;
for(auto [u, w] : g[v]) {
ll c = d + w;
if(c > 1e18) c = 1e18;
pq.push({-c, u});
}
}
}
return dist[0][1];
}
// int r[100][2], l[100], p[100];
// int main() {
// ios_base::sync_with_stdio(0); cin.tie(0);
// int N, M, K;
// cin >> N >> M >> K;
// for(int i = 0; i < M; i++) {
// cin >> r[i][0] >> r[i][1];
// }
// for(int i = 0; i < M; i++) cin >> l[i];
// for(int i = 0; i < K; i++) cin >> p[i];
// cout << travel_plan(N, M, r, l, K, p) << '\n';
// }
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4260 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
3 ms |
4340 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
3 ms |
4208 KB |
Output is correct |
8 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4260 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
3 ms |
4340 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
3 ms |
4208 KB |
Output is correct |
8 |
Correct |
3 ms |
4308 KB |
Output is correct |
9 |
Correct |
4 ms |
4852 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4436 KB |
Output is correct |
12 |
Correct |
7 ms |
5332 KB |
Output is correct |
13 |
Correct |
7 ms |
5328 KB |
Output is correct |
14 |
Correct |
2 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
3 ms |
4180 KB |
Output is correct |
3 |
Correct |
2 ms |
4260 KB |
Output is correct |
4 |
Correct |
2 ms |
4308 KB |
Output is correct |
5 |
Correct |
3 ms |
4340 KB |
Output is correct |
6 |
Correct |
2 ms |
4308 KB |
Output is correct |
7 |
Correct |
3 ms |
4208 KB |
Output is correct |
8 |
Correct |
3 ms |
4308 KB |
Output is correct |
9 |
Correct |
4 ms |
4852 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4436 KB |
Output is correct |
12 |
Correct |
7 ms |
5332 KB |
Output is correct |
13 |
Correct |
7 ms |
5328 KB |
Output is correct |
14 |
Correct |
2 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
739 ms |
90328 KB |
Output is correct |
17 |
Correct |
65 ms |
14492 KB |
Output is correct |
18 |
Correct |
88 ms |
15940 KB |
Output is correct |
19 |
Correct |
786 ms |
92632 KB |
Output is correct |
20 |
Correct |
500 ms |
84004 KB |
Output is correct |
21 |
Correct |
35 ms |
9016 KB |
Output is correct |
22 |
Correct |
449 ms |
48360 KB |
Output is correct |