#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
//#define int long long
#define Mp make_pair
//#define double double long
typedef vector<int> vi;
typedef vector<double> vd;
typedef pair<int,int> pii;
typedef vector<pii> vii;
const int maxN = 1e6, inf = 1e9, mod = 1e9+7;
#include "crocodile.h"
//#include "grader.cpp"
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[])
{
vii g[n];
for(int i = 0; i < m; i++){
g[r[i][0]].pb({r[i][1], l[i]});
g[r[i][1]].pb({r[i][0], l[i]});
}
int dp[n][2];
for(int i = 0; i < n; i++)dp[i][0] = dp[i][1] = inf;
for(int i = 0; i < k; i++)dp[p[i]][0] = dp[p[i]][1] = 0;
priority_queue<pii, vii, greater<pii>> q;
for(int i = 0; i < k; i++)q.push({0, p[i]});
while(!q.empty()){
auto [dis, x] = q.top();
q.pop();
if(dis > dp[x][0])continue;
for(auto [to, ct]:g[x]){
if(dp[to][1] > dp[x][1] + ct){
dp[to][1] = dp[x][1] + ct;
if(dp[to][1] < dp[to][0])swap(dp[to][1], dp[to][0]);
q.push({dp[x][1]+ct, to});
}
}
}
//for(int i = 0; i < n; i++)cout << dp[i][0] << ' ' << dp[i][1] << '\n';
return dp[0][1];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |