#include "crocodile.h"
#include<bits/stdc++.h>
#define ll long long
using namespace std;
vector<bool>is,vis;
vector<vector<pair<int,int>>>v;
vector<priority_queue<int>>dp;
const int INF=1e9;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
is.assign(N,false);
vis.assign(N,false);
for(int i=0;i<K;i++) is[P[i]]=true;
v.resize(N);
for(int i=0;i<M;i++){
v[R[i][0]].push_back({R[i][1],L[i]});
v[R[i][1]].push_back({R[i][0],L[i]});
}
dp.resize(N);
priority_queue<array<int,3>>q;
for(int i=0;i<K;i++){
q.push({2,0,P[i]});
dp[P[i]].push(0);
}
while(!q.empty()){
auto [sz,d,x]=q.top();
q.pop();
if(vis[x]) continue;
vis[x]=true;
for(auto [z,w]:v[x]){
if(dp[z].size()<2){
dp[z].push(dp[x].top()+w);
q.push({(int)dp[z].size(),-dp[z].top(),z});
}
else if(dp[x].top()+w<dp[z].top()){
dp[z].pop();
dp[z].push(dp[x].top()+w);
q.push({(int)dp[z].size(),-dp[z].top(),z});
}
}
}
return dp[0].top();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
1 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
600 KB |
Output is correct |
9 |
Incorrect |
2 ms |
604 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |