#include<bits/stdc++.h>
#define taskname "A"
using namespace std;
const int MOD = 1e9 + 7;
const int MAXN = 2e5 + 10;
const int INF = 1e9;
int par[MAXN]; vector<pair<int, int64_t>> G[MAXN];
int64_t travel_plan(int N, int M, int R[][2], int L[], int K, int st[]){
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 ++) {
G[R[i][0]].push_back(make_pair(R[i][1], L[i]));
G[R[i][1]].push_back(make_pair(R[i][0], L[i]));
}
priority_queue<pair<int64_t, int>> pq;
vector<int64_t> f(N + 5, 1e18);
for (int i = 0; i < K; i ++) {
cin >> st[i]; f[st[i]] = 0;
pq.push(make_pair(0, st[i]));
}
while (!pq.empty()) {
int64_t d; int u; tie(d, u) = pq.top(); pq.pop();
if (-d != f[u]) continue;
for (auto [v, w] : G[u]) {
if (f[v] > f[u] + w) {
f[v] = f[u] + w;
par[v] = u;
pq.push(make_pair(-f[v], v));
}
}
}
for (int i = 0; i < N; i ++) f[i] = 1e18;
f[0] = 0; pq.push(make_pair(f[0], 0));
while (!pq.empty()) {
int64_t d; int u; tie(d, u) = pq.top(); pq.pop();
if (-d != f[u]) continue;
for (auto [v, w] : G[u]) {
if (par[u] != v && f[v] > f[u] + w) {
f[v] = f[u] + w;
pq.push(make_pair(-f[v], v));
}
}
}
int64_t ans = 1e18;
for (int i = 0; i < K; i ++) {
ans = min(ans, f[st[i]]);
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
3 ms |
8792 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |