Submission #1311657

#TimeUsernameProblemLanguageResultExecution timeMemory
1311657kawhietRace (IOI11_race)C++20
0 / 100
1 ms572 KiB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;

constexpr long long inf = 1e6 + 5;

int best_path(int N, int K, int H[][2], int L[]) {
    vector<vector<pair<int, int>>> g(N);
    for (int i = 0; i < N - 1; i++) {
        int u = H[i][0], v = H[i][1], w = L[i];
        g[u].push_back({v, w});
        g[v].push_back({u, w});
    }
    int ans = inf;
    for (int i = 0; i < N; i++) {
        vector<int> d(N, inf);
        vector<long long> cost(N);
        queue<int> q;
        d[i] = 0;
        q.push(i);
        while (!q.empty()) {
            int u = q.front();
            q.pop();
            for (auto [v, w] : g[u]) {
                if (d[v] == inf) {
                    d[v] = d[u] + 1;
                    cost[v] = cost[u] + w;
                    q.push(v);
                }
            }
        }
        for (int j = 0; j < N; j++) {
            if (cost[j] == K) {
                ans = min(ans, d[j]);
            }
        }
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...