#include "crocodile.h"
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5+5;
#define all(x) x.begin(), x.end()
#define mk make_pair
#define pb push_back
#define fr first
#define sc second
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]) {
int min_cost[N], cost[N];
bool vis[N];
vector<pii> edges[N];
memset(vis, 0, sizeof(vis));
fill(cost, cost+N, 1e9+7);
fill(min_cost, min_cost+N, 1e9+7);
for(int i = 0; i < M; i++)
edges[R[i][0]].pb({R[i][1], L[i]}), edges[R[i][1]].pb({R[i][0], L[i]});
priority_queue<pii, vector<pii>, greater<pii>> pq;
for(int i = 0; i < K; i++)
pq.push({0, P[i]}), min_cost[P[i]] = cost[P[i]] = 0;
while(!pq.empty()) {
auto [d, x] = pq.top();
pq.pop();
if(vis[x]) continue;
vis[x] = 1;
for(auto [viz, peso] : edges[x]) {
cost[viz] = min(cost[viz], max(min_cost[viz], d + peso));
min_cost[viz] = min(min_cost[viz], d + peso);
if(cost[viz] < 1e9+7) pq.push({cost[viz], viz});
}
}
return cost[0];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 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 |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 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 |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
5 ms |
4952 KB |
Output is correct |
13 |
Correct |
4 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4440 KB |
Output is correct |
15 |
Correct |
2 ms |
4820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4440 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
2 ms |
4444 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 |
4696 KB |
Output is correct |
8 |
Correct |
1 ms |
4440 KB |
Output is correct |
9 |
Correct |
3 ms |
4696 KB |
Output is correct |
10 |
Correct |
1 ms |
4440 KB |
Output is correct |
11 |
Correct |
2 ms |
4444 KB |
Output is correct |
12 |
Correct |
5 ms |
4952 KB |
Output is correct |
13 |
Correct |
4 ms |
4952 KB |
Output is correct |
14 |
Correct |
2 ms |
4440 KB |
Output is correct |
15 |
Correct |
2 ms |
4820 KB |
Output is correct |
16 |
Correct |
570 ms |
57232 KB |
Output is correct |
17 |
Correct |
59 ms |
14160 KB |
Output is correct |
18 |
Correct |
79 ms |
15696 KB |
Output is correct |
19 |
Correct |
626 ms |
57636 KB |
Output is correct |
20 |
Correct |
423 ms |
46532 KB |
Output is correct |
21 |
Correct |
31 ms |
8788 KB |
Output is correct |
22 |
Correct |
386 ms |
39324 KB |
Output is correct |