/**
____ ____ ____ ____ ____
||a |||t |||o |||d |||o ||
||__|||__|||__|||__|||__||
|/__\|/__\|/__\|/__\|/__\|
**/
#include <bits/stdc++.h>
#include "crocodile.h"
using namespace std;
typedef long long ll;
const int INF = INT_MAX / 2;
struct Edge
{
int to;
int len;
};
struct Path
{
int to;
int len;
};
bool operator < (const Path &p1, const Path &p2)
{
return p1.len > p2.len;
}
int travel_plan (int N, int M, int R[][2], int L[], int K, int P[])
{
vector <vector <Edge>> adj (N);
for(int i = 0; i < M; i++)
{
adj[R[i][0]].push_back(Edge{R[i][1], L[i]});
adj[R[i][1]].push_back(Edge{R[i][0], L[i]});
}
vector <bool> visited (N, false);
vector <int> dist1 (N, INF);
vector <int> dist2 (N, INF);
priority_queue <Path> q;
for(int i = 0; i < K; i++)
{
dist1[P[i]] = dist2[P[i]] = 0;
q.push(Path{P[i], 0});
}
while(q.empty() == false)
{
Path p = q.top();
q.pop();
if(visited[p.to] == true)
break;
visited[p.to] = true;
for(Edge e : adj[p.to])
if(visited[e.to] == false)
{
if(dist2[p.to] + e.len <= dist1[e.to])
{
dist2[e.to] = dist1[e.to];
dist1[e.to] = dist2[p.to] + e.len;
}
else if(dist2[p.to] + e.len < dist2[e.to])
{
dist2[e.to] = dist2[p.to] + e.len;
}
if(dist2[e.to] != INF)
q.push(Path{e.to, dist2[e.to]});
}
}
return dist2[0];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |