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>
#include "crocodile.h"
using namespace std;
typedef long long ll;
const int MAX = 2e6 + 15;
const ll INF = 5e18 + 50;
#define fr first
#define sc second
ll dist[MAX][2], ans;
bool seen[MAX];
vector<pair<ll, ll>> adj[MAX];
int travel_plan(int n, int m, int R[][2], int L[], int k, int P[]){
for(int i = 0; i < m; i++){
ll u = R[i][0], v = R[i][1], w = L[i];
adj[u].push_back({v, w});
adj[v].push_back({u, w});
}
for(int i = 0; i < n; i++)
dist[i][0] = dist[i][1] = INF;
priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>> q;
for(int i = 0; i < k; i++){
dist[P[i]][0] = dist[P[i]][1] = 0;
q.push({0, P[i]});
}
while(q.size()){
ll u = q.top().sc; q.pop();
if(seen[u]) continue;
seen[u] = true;
for(auto e : adj[u]){
ll v = e.fr, w = e.sc;
if(dist[u][1] + w < dist[v][0]){
swap(dist[v][1], dist[v][0]);
dist[v][0] = dist[u][1] + w;
q.push({dist[v][0], v});
}else if(dist[u][1] + w < dist[v][1]){
dist[v][1] = dist[u][1] + w;
q.push({dist[v][1], v});
}
}
}
return dist[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... |