#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
vector <pair <int, int>> adj[N];
bool special[N];
int n, m, k;
namespace sub2 {
long long d[N][2];
struct state {
long long dist;
int u, t;
bool operator < (const state &other) const {
return dist > other.dist;
}
};
long long solve() {
priority_queue <state> heap;
memset(d, 0x3f, sizeof d);
for (int i = 0; i < n; ++i) {
if (special[i] == false) continue;
d[i][0] = d[i][1] = 0;
heap.push({0, i, 0});
}
while (heap.size()) {
auto [dist, u, t] = heap.top();
heap.pop();
if (dist != d[u][t]) continue;
for (auto [v, w] : adj[u]) {
if (d[v][0] > dist + w) {
if (d[v][0] < (long long) 1e18 && d[v][1] != d[v][0]) {
d[v][1] = d[v][0];
heap.push({d[v][1], v, 1});
}
d[v][0] = dist + w;
} else if (d[v][1] > dist + w) {
d[v][1] = dist + w;
heap.push({dist + w, v, 1});
}
}
}
return d[0][1];
}
}
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 < m; ++i) {
int u = R[i][0], v = R[i][1], w = L[i];
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
for (int i = 0; i < k; ++i) {
special[P[i]] = true;
}
return sub2::solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
4 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4308 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
4180 KB |
Output is correct |
2 |
Correct |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
4 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4308 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
4 ms |
4436 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
5 ms |
4564 KB |
Output is correct |
13 |
Correct |
5 ms |
4564 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 |
2 ms |
4180 KB |
Output is correct |
3 |
Correct |
3 ms |
4180 KB |
Output is correct |
4 |
Correct |
3 ms |
4308 KB |
Output is correct |
5 |
Correct |
4 ms |
4308 KB |
Output is correct |
6 |
Correct |
2 ms |
4180 KB |
Output is correct |
7 |
Correct |
3 ms |
4308 KB |
Output is correct |
8 |
Correct |
3 ms |
4180 KB |
Output is correct |
9 |
Correct |
4 ms |
4436 KB |
Output is correct |
10 |
Correct |
2 ms |
4180 KB |
Output is correct |
11 |
Correct |
3 ms |
4308 KB |
Output is correct |
12 |
Correct |
5 ms |
4564 KB |
Output is correct |
13 |
Correct |
5 ms |
4564 KB |
Output is correct |
14 |
Correct |
2 ms |
4180 KB |
Output is correct |
15 |
Correct |
3 ms |
4308 KB |
Output is correct |
16 |
Correct |
391 ms |
43468 KB |
Output is correct |
17 |
Correct |
63 ms |
11212 KB |
Output is correct |
18 |
Correct |
76 ms |
12484 KB |
Output is correct |
19 |
Correct |
487 ms |
47680 KB |
Output is correct |
20 |
Correct |
264 ms |
38176 KB |
Output is correct |
21 |
Correct |
36 ms |
7500 KB |
Output is correct |
22 |
Correct |
256 ms |
33184 KB |
Output is correct |