This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// looking to shine brighter in this world...
#define TASK "race"
#include "race.h"
#ifdef LOCAL
#include "local.h"
#else
#include <bits/stdc++.h>
#define debug(...)
#define DB(...)
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi first
#define se second
#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)
#define Fe(...) for (auto __VA_ARGS__)
template <class C> inline int isz(const C& c) { return static_cast<int>(c.size()); }
template <class T> inline bool chmin(T& a, const T& b) { return (a > b) ? a = b, true : false; }
template <class T> inline bool chmax(T& a, const T& b) { return (a < b) ? a = b, true : false; }
const bool __initialization = []() {
cin.tie(nullptr)->sync_with_stdio(false);
if (fopen(TASK".inp", "r")) {
(void)(!freopen(TASK".inp", "r", stdin));
(void)(!freopen(TASK".out", "w", stdout)); }
cout << setprecision(12) << fixed;
return true;
}();
constexpr ld eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;
// ================================================================================
constexpr int maxn = 2e5 + 5;
struct Info { int v, c; };
struct State { int u, i; };
vector<Info> g[maxn];
ll d[maxn];
queue<State> q;
int Bfs(int src, int n, int k) {
memset(d, -1, sizeof(d[0]) * n); d[src] = 0;
q.push({ src, 0 });
int ret = inf;
while (isz(q)) {
State s = q.front(); q.pop();
if (d[s.u] > k) {
continue;
}
else if (d[s.u] == k) {
chmin(ret, s.i);
continue;
}
Fe (&[v, c] : g[s.u]) {
if (d[v] != -1) continue;
if (d[s.u] + c > k) continue;
d[v] = d[s.u] + c;
q.push({ v, s.i + 1 });
}
}
return ret;
}
int best_path(int n, int k, int h[][2], int l[]) {
Rep (i, n - 1) {
int u = h[i][0];
int v = h[i][1];
int c = l[i];
g[u].push_back({ v, c });
g[v].push_back({ u, c });
}
int ans = inf;
Rep (u, n) {
chmin(ans, Bfs(u, n, k));
}
if (ans == inf) ans = -1;
return ans;
}
# | 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... |