#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef pair<int, int> pi;
#define MOD 1000000007LL
vector<pair<int, int>> adj[100000];
ll dis[100000];
pair<ll, ll> mdis[100000];
int travel_plan(int N, int M, int R[][2], int *L, int K, int *P) {
//cout << "Debugging: " << N << " " << M << " " << K << endl;
//for (int i = 0; i < M; i++) cout << R[i][0] << " " << R[i][1] << endl;
//for (int i = 0; i < M; i++) cout << L[i] << " "; cout << endl;
//for (int i = 0; i < K; i++) cout << P[i] << " "; cout << endl;
for (int i = 0; i < N; i++) { adj[i].clear(); dis[i] = 1e18; mdis[i] = {1e18, 1e18}; }
for (int i = 0; i < M; i++) {
int a = R[i][0], b = R[i][1], w = L[i];
adj[a].push_back({b, w});
adj[b].push_back({a, w});
}
using T = pair<ll, ll>; priority_queue<T, vector<T>, greater<T>> q;
for (int i = 0; i < K; i++) { q.push({0, P[i]}); dis[P[i]] = 0; }
while (!q.empty()) {
ll v = q.top().second, ow = q.top().first; q.pop();
if (dis[v] < ow) continue;
for (auto pp : adj[v]) {
ll u = pp.first, w = pp.second;
if (dis[v]+w <= mdis[u].first) {
mdis[u].second = mdis[u].first;
mdis[u].first = dis[v]+w;
} else if (dis[v]+w <= mdis[u].second) {
mdis[u].second = dis[v]+w;
}
if (mdis[u].second < dis[u]) {
dis[u] = mdis[u].second;
q.push({dis[u], u});
}
}
//cout << "processed: " << v << " " << dis[v] << endl;
}
//cout << "Debugging dis, mdis" << endl;
//for (int i = 0; i < N; i++) cout << dis[i] << " "; cout << endl;
//for (int i = 0; i < N; i++) cout << mdis[i].first << " "; cout << endl;
//for (int i = 0; i < N; i++) cout << mdis[i].second << " "; cout << endl;
return dis[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2924 KB |
Output is correct |
9 |
Correct |
4 ms |
3052 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2796 KB |
Output is correct |
12 |
Correct |
6 ms |
3308 KB |
Output is correct |
13 |
Correct |
5 ms |
3180 KB |
Output is correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Correct |
3 ms |
2796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2668 KB |
Output is correct |
2 |
Correct |
2 ms |
2668 KB |
Output is correct |
3 |
Correct |
2 ms |
2688 KB |
Output is correct |
4 |
Correct |
3 ms |
2796 KB |
Output is correct |
5 |
Correct |
3 ms |
2796 KB |
Output is correct |
6 |
Correct |
3 ms |
2796 KB |
Output is correct |
7 |
Correct |
3 ms |
2796 KB |
Output is correct |
8 |
Correct |
3 ms |
2924 KB |
Output is correct |
9 |
Correct |
4 ms |
3052 KB |
Output is correct |
10 |
Correct |
2 ms |
2668 KB |
Output is correct |
11 |
Correct |
3 ms |
2796 KB |
Output is correct |
12 |
Correct |
6 ms |
3308 KB |
Output is correct |
13 |
Correct |
5 ms |
3180 KB |
Output is correct |
14 |
Correct |
2 ms |
2668 KB |
Output is correct |
15 |
Correct |
3 ms |
2796 KB |
Output is correct |
16 |
Correct |
510 ms |
59360 KB |
Output is correct |
17 |
Correct |
79 ms |
15340 KB |
Output is correct |
18 |
Correct |
119 ms |
16888 KB |
Output is correct |
19 |
Correct |
670 ms |
65140 KB |
Output is correct |
20 |
Correct |
301 ms |
49644 KB |
Output is correct |
21 |
Correct |
39 ms |
8172 KB |
Output is correct |
22 |
Correct |
329 ms |
46524 KB |
Output is correct |