#include<bits/stdc++.h>
using namespace std;
#define ALL(a) a.begin(), a.end()
using pii = pair<int, int>;
const int N = 1e5 + 5;
vector<pii> adj[N];
int cnt[N];
void connect(int u, int v, int w) {
adj[u].emplace_back(v, w);
adj[v].emplace_back(u, w);
}
int travel_plan(int n, int nEdges, int R[][2], int l[], int nExits, int a[]) {
priority_queue<pii, vector<pii>, greater<pii>> Q;
for(int i = 0; i < nEdges; i++)
connect(R[i][0], R[i][1], l[i]);
for(int i = 0; i < nExits; i++) {
cnt[a[i]]++;
Q.emplace(0, a[i]);
}
for(int i = 0; i < n; i++)
sort(ALL(adj[i]), [&](pii a, pii b) {
return a.second < b.second;
});
int ans = -1;
while(!Q.empty()) {
auto [weight, u] = Q.top();
Q.pop();
cnt[u]++;
if(cnt[u] == 2) {
if(u == 0) {
ans = weight;
break;
}
for(auto [v, w] : adj[u]) {
if(cnt[v] < 2)
Q.emplace(weight + w, v);
}
}
}
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6620 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6620 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6628 KB |
Output is correct |
12 |
Correct |
4 ms |
7004 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
14 |
Correct |
1 ms |
6604 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
6492 KB |
Output is correct |
2 |
Correct |
1 ms |
6492 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
2 ms |
6492 KB |
Output is correct |
6 |
Correct |
1 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6620 KB |
Output is correct |
8 |
Correct |
1 ms |
6492 KB |
Output is correct |
9 |
Correct |
2 ms |
6748 KB |
Output is correct |
10 |
Correct |
1 ms |
6492 KB |
Output is correct |
11 |
Correct |
1 ms |
6628 KB |
Output is correct |
12 |
Correct |
4 ms |
7004 KB |
Output is correct |
13 |
Correct |
3 ms |
7004 KB |
Output is correct |
14 |
Correct |
1 ms |
6604 KB |
Output is correct |
15 |
Correct |
1 ms |
6492 KB |
Output is correct |
16 |
Correct |
297 ms |
69660 KB |
Output is correct |
17 |
Correct |
46 ms |
16732 KB |
Output is correct |
18 |
Correct |
50 ms |
18092 KB |
Output is correct |
19 |
Correct |
284 ms |
72092 KB |
Output is correct |
20 |
Correct |
187 ms |
54096 KB |
Output is correct |
21 |
Correct |
25 ms |
10332 KB |
Output is correct |
22 |
Correct |
293 ms |
49748 KB |
Output is correct |