#include "crocodile.h"
#include <stdio.h>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]);
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[])
{
long long dist[N];
for(int i=0; i<N; i++) dist[i] = 1e15;
for(int i=0; i<K; i++) dist[P[i]] = 0;
bool vis[N];
for(int i=0; i<N; i++) vis[i] = 0;
priority_queue<pair<long long, int>, vector<pair<long long, int> >, greater<pair<long long, int> > >pq;
for(int i=0; i<N; i++) pq.push({dist[i], i});
vector<pair<int, long long> > adj[N];
for(int i=0; i<M; i++) {
adj[R[i][0]].push_back({R[i][1], L[i]});
adj[R[i][1]].push_back({R[i][0], L[i]});
}
while(pq.size()) {
pair<long long, int> t = pq.top(); pq.pop();
if(!vis[t.second]) {
vis[t.second] = 1;
for(pair<int, long long> x : adj[t.second]) {
if(!vis[x.first] && dist[t.second] != 1e15 && dist[x.first] > dist[t.second] + x.second) {
dist[x.first] = dist[t.second] + x.second;
pq.push({dist[x.first], x.first});
}
}
}
}
long long dp[N];
for(int i=0; i<N; i++) dp[i] = 1e15;
pair<long long, int> p[N];
for(int i=0; i<N; i++) p[i] = {dist[i], i};
sort(p, p+N);
for(int i=0; i<N; i++) {
if(p[i].first == 0) {
dp[p[i].second] = 0;
}
else {
vector<long long> v;
for(pair<int, long long> x : adj[p[i].second]) {
if(dp[x.first] != 1e15) {
v.push_back(dp[x.first] + x.second);
}
}
sort(v.begin(), v.end());
if(v.size() > 1) {
dp[p[i].second] = v[1];
}
}
}
return (int)dp[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |