Submission #1000834

# Submission time Handle Problem Language Result Execution time Memory
1000834 2024-06-18T09:53:33 Z ALTAKEXE Race (IOI11_race) C++17
31 / 100
352 ms 262144 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
 
#define ff  first
#define ss  second
#define pii pair<int, int>
 
int k, mn = INT_MAX;
 
vector<vector<int>> dp;
 
vector<vector<pii>> v, E;
 
void dfs(int x, int p = - 1) {
    dp[x][0] = 0;
 
    for (auto [i, w] : E[x])
        if (i != p) dfs(i, x);
 
    v.assign(k + 1, {});
    for (auto [i, w] : E[x]) {
        if (i == p) continue;
 
        for (int j = w; j <= k; j++) {
            if (dp[i][j - w] == INT_MAX) continue;
 
            if ((int)v[j].size() < 2) v[j].push_back({dp[i][j - w] + 1, i});
            else if (dp[i][j - w] + 1 < v[j][1].ff) v[j][1] = {dp[i][j - w] + 1, i};
            
            if ((int)v[j].size() == 2 && v[j][0].ff > v[j][1].ff) swap(v[j][0], v[j][1]);
 
            dp[x][j] = min(dp[x][j], dp[i][j - w] + 1);
        }
    }
 
    if (!v[k].empty()) mn = min(mn, (int)v[k][0].ff);
    for (int i = 1; i < k; i++) {
        if (v[i].empty() || v[k - i].empty()) continue;
 
        if (v[i][0].ss != v[k - i][0].ss) mn = min(mn, v[i][0].ff + v[k - i][0].ff);
        else if (1 < (int)v[k - i].size()) mn = min(mn, v[i][0].ff + v[k - i][1].ff);
    }
}
 
int best_path(int N, int K, int H[][2], int L[]) {
    k = K;
 
    E.assign(N, {});
    for (int i = 0; i < N - 1; i++) {
        E[H[i][0]].push_back({H[i][1], L[i]});
        E[H[i][1]].push_back({H[i][0], L[i]});
    }
 
    dp.assign(N, vector<int>(k + 1, INT_MAX));
    dfs(0);
 
    return (mn == INT_MAX ? -1 : mn);
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 5 ms 5608 KB Output is correct
22 Runtime error 111 ms 262144 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 126 ms 53592 KB Output is correct
20 Correct 126 ms 53584 KB Output is correct
21 Correct 122 ms 53584 KB Output is correct
22 Correct 120 ms 53780 KB Output is correct
23 Correct 108 ms 53844 KB Output is correct
24 Correct 102 ms 53916 KB Output is correct
25 Correct 201 ms 60500 KB Output is correct
26 Correct 175 ms 67152 KB Output is correct
27 Correct 224 ms 93000 KB Output is correct
28 Correct 250 ms 129616 KB Output is correct
29 Correct 246 ms 124652 KB Output is correct
30 Correct 220 ms 93264 KB Output is correct
31 Correct 232 ms 93228 KB Output is correct
32 Correct 277 ms 102724 KB Output is correct
33 Correct 352 ms 101456 KB Output is correct
34 Correct 211 ms 101284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 1 ms 2392 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 1 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 1 ms 2396 KB Output is correct
9 Correct 1 ms 2392 KB Output is correct
10 Correct 1 ms 2396 KB Output is correct
11 Correct 1 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 1 ms 2396 KB Output is correct
14 Correct 1 ms 2396 KB Output is correct
15 Correct 0 ms 2396 KB Output is correct
16 Correct 1 ms 2396 KB Output is correct
17 Correct 1 ms 2396 KB Output is correct
18 Correct 0 ms 2396 KB Output is correct
19 Correct 0 ms 2396 KB Output is correct
20 Correct 1 ms 2396 KB Output is correct
21 Correct 5 ms 5608 KB Output is correct
22 Runtime error 111 ms 262144 KB Execution killed with signal 9
23 Halted 0 ms 0 KB -