# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
252607 | Kubin | Race (IOI11_race) | C++11 | 3091 ms | 10332 KiB |
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 <bits/stdc++.h>
using namespace std;
int best_path(int _n, int k, int ends[][2], int weight[])
{
const size_t n = _n;
vector<vector<pair<size_t, int>>> adj(n);
for(size_t i = 0; i < n - 1; i++)
{
size_t u = ends[i][0], v = ends[i][1];
adj[u].emplace_back(v, weight[i]);
adj[v].emplace_back(u, weight[i]);
}
function<pair<size_t, int>(size_t, size_t, size_t)> dfs = [&](size_t u, size_t t, size_t lock) -> pair<size_t, int> {
if(u == t)
return {0, 0};
for(auto [v, w] : adj[u])
if(v != lock)
{
auto [d, ww] = dfs(v, t, u);
if(d != SIZE_MAX)
return make_pair(d + 1, ww + w);
}
return {SIZE_MAX, 0};
};
size_t result = SIZE_MAX;
for(size_t u = 0; u < n; u++)
for(size_t v = 0; v < u; v++)
{
auto [d, w] = dfs(u, v, SIZE_MAX);
if(w == k)
result = min(result, d);
}
return result;
}
Compilation message (stderr)
# | 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... |