#include <bits/stdc++.h>
using namespace std;
// [node cnt, edge cnt, edges, vals, exit cnt, exits]
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
vector <pair <int, int>> adj[N];
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);
}
using T = pair <int, int>;
priority_queue <T, vector <T>, greater <T>> pq;
vector <int> cnt(N);
vector <int> special(N);
vector <int> ans(N, -1);
for(int i = 0; i < K; i++) {
int node = P[i];
special[node] = true;
pq.emplace(0, node);
}
while(!pq.empty()) {
auto [c, node] = pq.top();
pq.pop();
cnt[node]++;
if(special[node]) {
if(cnt[node] != 1) {
continue;
}
} else {
if(cnt[node] != 2) {
continue;
}
}
ans[node] = c;
for(auto [child, w] : adj[node]) {
pq.emplace(c + w, child);
}
}
return ans[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4548 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4552 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4548 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4552 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4544 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
5212 KB |
Output is correct |
13 |
Correct |
5 ms |
5212 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4496 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4548 KB |
Output is correct |
4 |
Correct |
1 ms |
4440 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4440 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4552 KB |
Output is correct |
9 |
Correct |
3 ms |
4952 KB |
Output is correct |
10 |
Correct |
1 ms |
4544 KB |
Output is correct |
11 |
Correct |
2 ms |
4700 KB |
Output is correct |
12 |
Correct |
6 ms |
5212 KB |
Output is correct |
13 |
Correct |
5 ms |
5212 KB |
Output is correct |
14 |
Correct |
1 ms |
4444 KB |
Output is correct |
15 |
Correct |
1 ms |
4496 KB |
Output is correct |
16 |
Correct |
600 ms |
72392 KB |
Output is correct |
17 |
Correct |
63 ms |
15952 KB |
Output is correct |
18 |
Correct |
89 ms |
17188 KB |
Output is correct |
19 |
Correct |
659 ms |
77804 KB |
Output is correct |
20 |
Correct |
474 ms |
64528 KB |
Output is correct |
21 |
Correct |
33 ms |
9300 KB |
Output is correct |
22 |
Correct |
423 ms |
46756 KB |
Output is correct |