#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using ll = long long;
const ll inf = 1e15;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
vector<vector<pair<ll, int>>> dx(n);
vector<vector<ll>> dp(n, vector<ll>(2, inf));
vector<bool> viz(n);
for(int i=0; i<m; i++) {
dx[r[i][0]].emplace_back(l[i], r[i][1]);
dx[r[i][1]].emplace_back(l[i], r[i][0]);
}
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
for(int i=0; i<k; i++) {
pq.emplace(0, p[i]);
dp[p[i]][0] = 0;
dp[p[i]][1] = 0;
}
while(pq.empty() == false) {
pair<ll, int> temp = pq.top(); pq.pop();
ll cost = temp.first;
int u = temp.second;
if(viz[u]) continue;
viz[u] = true;
for(auto i : dx[u]) {
ll nc = cost + i.first;
int v = i.second;
if(dp[v][0] > nc) {
dp[v][1] = dp[v][0];
dp[v][0] = nc;
pq.emplace(dp[v][1], v);
}
else if(dp[v][1] > nc) {
dp[v][1] = nc;
pq.emplace(dp[v][1], v);
}
}
}
return dp[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
980 KB |
Output is correct |
13 |
Correct |
3 ms |
1084 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
312 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
1 ms |
444 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
3 ms |
980 KB |
Output is correct |
13 |
Correct |
3 ms |
1084 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
468 KB |
Output is correct |
16 |
Correct |
425 ms |
85176 KB |
Output is correct |
17 |
Correct |
87 ms |
23672 KB |
Output is correct |
18 |
Correct |
113 ms |
26176 KB |
Output is correct |
19 |
Correct |
551 ms |
97116 KB |
Output is correct |
20 |
Correct |
250 ms |
65348 KB |
Output is correct |
21 |
Correct |
52 ms |
9936 KB |
Output is correct |
22 |
Correct |
294 ms |
64124 KB |
Output is correct |