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;
int n, res;
vector<long long> dist(sz), dep(sz, 0);
vector<vector<pair<int, int>>> adj(sz);
int dij(int s, int need, int n) {
vector<long long> dist(n, LLONG_MAX);
vector<int> dep(n, INT_MAX);
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> q;
dist[s] = 0;
dep[s] = 0;
q.push({0, s});
while (!q.empty()) {
int v = q.top().second;
long long d_v = q.top().first;
q.pop();
if (d_v != dist[v]) {
continue;
}
if (dist[v] == need) {
return dep[v];
}
for (auto i : adj[v]) {
int u = i.first;
int weight = i.second;
if (dist[u] > dist[v] + weight) {
dist[u] = dist[v] + weight;
dep[u] = dep[v] + 1;
q.push({dist[u], u});
}
}
}
return INT_MAX;
}
int best_path(int N, int K, int H[][2], int L[]) {
if (K == 1) {
return 0;
}
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]});
}
int res = INT_MAX;
for (int i = 0; i < N; ++i) {
int path_length = dij(i, K, N);
res = min(res, path_length);
}
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... |