#include "bits/stdc++.h"
using namespace std;
#define s second
#define f first
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
vector<vector<pii> > adj(n);
for (int i = 0; i < m; i++) {
adj[r[i][0]].pb({r[i][1], l[i]});
adj[r[i][1]].pb({r[i][0], l[i]});
}
vector<int> d1(n, -1);
vector<int> d2(n, -1);
priority_queue<pii> q;
for (int i = 0; i < k; i++) {
d1[p[i]] = 0;
d2[p[i]] = 0;
for (auto val: adj[p[i]]) q.push({-val.s, val.f});
}
while (!q.empty()) {
int cur, dist;
tie(dist, cur) = q.top();
q.pop();
if (d1[cur] == -1) {
d1[cur] = -dist;
continue;
} else if (d2[cur] == -1) {
d2[cur] = -dist;
} else {
continue;
}
for (auto val: adj[cur]) {
q.push({dist - val.s, val.f});
}
}
return d2[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
1084 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
572 KB |
Output is correct |
12 |
Correct |
6 ms |
1592 KB |
Output is correct |
13 |
Correct |
5 ms |
1756 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
484 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
448 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
2 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
3 ms |
1084 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
572 KB |
Output is correct |
12 |
Correct |
6 ms |
1592 KB |
Output is correct |
13 |
Correct |
5 ms |
1756 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
484 KB |
Output is correct |
16 |
Correct |
921 ms |
112024 KB |
Output is correct |
17 |
Correct |
87 ms |
16844 KB |
Output is correct |
18 |
Correct |
116 ms |
19288 KB |
Output is correct |
19 |
Correct |
980 ms |
117280 KB |
Output is correct |
20 |
Correct |
650 ms |
98744 KB |
Output is correct |
21 |
Correct |
41 ms |
7864 KB |
Output is correct |
22 |
Correct |
533 ms |
63260 KB |
Output is correct |