This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |