#include <bits/stdc++.h>
//#include "grader.h"
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
const int maxn = 100001, maxm = 1000001, INF = 2e9;
vector<vector<pi>> adj(maxn);
int dist[maxn][2];
set<pi> s;
int travel_plan(int N, int M, int R[][2], int L[], int K, int P[]){
for(int i = 0; i < M; i++){
adj[R[i][0]].pb({R[i][1], L[i]});
adj[R[i][1]].pb({R[i][0], L[i]});
}
for(int i = 0; i <= N; i++)
dist[i][0] = dist[i][1] = INF;
for(int i = 0; i < K; i++){
dist[P[i]][0] = dist[P[i]][1] = 0;
s.insert({0, P[i]});
}
while(!s.empty()){
int a = s.begin()->second;
s.erase(s.begin());
for(auto i : adj[a]){
int b = i.f, w = i.s;
if(dist[b][0] > dist[a][1] + w){
dist[b][1] = dist[b][0];
dist[b][0] = dist[a][1] + w;
if(dist[b][1] != INF)
s.insert({dist[b][1], b});
} else if(dist[b][1] > dist[a][1] + w){
dist[b][1] = dist[a][1] + w;
s.insert({dist[b][1], b});
}
}
}
return dist[0][1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2676 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |