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 "race.h"
#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 5;
vector<vector<pair<int,int>>>adj(sz);
int n, res;
vector<long long> dist(sz), dep(sz, 0);
void dij(int s,int need){
dist.assign(sz, INT_MAX);
dep.assign(sz, INT_MAX);
priority_queue<pair<int,int>, vector<pair<int,int>>, greater<pair<int,int>>>q;
dep[s] = 0;
q.push({0, s});
while(!q.empty()){
int v = q.top().second;
int d_v = q.top().first;
if(d_v != dist[v]){
continue;
}
if(dist[v] == need){
res = min(1LL * res, dep[v]);
return;
}
for(auto i : adj[v]){
if(dist[i.first] > dist[v] + i.second){
dep[i.first] = dep[v] + 1;
dist[i.first] = dist[v] + i.second;
q.push({dist[i.first], i.first});
}
}
}
}
int best_path(int N, int K, int H[][2], int L[])
{
if(K == 1){
return 0;
}
n = N;
for(int i = 0; i < n; ++i){
adj[H[i][0]].push_back({H[i][1], L[i]});
adj[H[i][1]].push_back({H[i][0], L[i]});
}
res = INT_MAX;
for(int i = 0; i < n; ++i){
dij(i, K);
}
return (res == INT_MAX ? -1 : res);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |