이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
using ll = long long;
const ll inf = 1e15;
int travel_plan(int n, int m, int r[][2], int l[], int k, int p[]) {
vector<vector<pair<ll, int>>> dx(n);
vector<vector<ll>> dp(n, vector<ll>(2, inf));
vector<bool> viz(n);
for(int i=0; i<m; i++) {
dx[r[i][0]].emplace_back(l[i], r[i][1]);
dx[r[i][1]].emplace_back(l[i], r[i][0]);
}
priority_queue<pair<ll, int>, vector<pair<ll, int>>, greater<pair<ll, int>>> pq;
for(int i=0; i<k; i++) {
pq.emplace(0, p[i]);
dp[p[i]][0] = 0;
dp[p[i]][1] = 0;
}
while(pq.empty() == false) {
pair<ll, int> temp = pq.top(); pq.pop();
ll cost = temp.first;
int u = temp.second;
if(viz[u]) continue;
viz[u] = true;
for(auto i : dx[u]) {
ll nc = cost + i.first;
int v = i.second;
if(dp[v][0] > nc) {
dp[v][1] = dp[v][0];
dp[v][0] = nc;
pq.emplace(dp[v][1], v);
}
else if(dp[v][1] > nc) {
dp[v][1] = nc;
pq.emplace(dp[v][1], v);
}
}
}
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... |