Submission #1006190

# Submission time Handle Problem Language Result Execution time Memory
1006190 2024-06-23T14:15:44 Z c2zi6 Race (IOI11_race) C++14
100 / 100
347 ms 103452 KB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "race.h"

int n;
ll k;
VVPI gp;
VL dist;
VI depth;
vector<map<ll, int>> st;

void dfs1(int u = 0, int p = -1) {
    for (auto[v, w] : gp[u]) if (v != p) {
        depth[v] = depth[u]+1;
        dist[v] = dist[u] + w;
        dfs1(v, u);
    }
}

int ans = 2e9;
void dfs2(int u = 0, int p = -1) {
    st[u][dist[u]] = depth[u];
    for (auto[v, w] : gp[u]) if (v != p) {
        dfs2(v, u);
        if (st[v].size() > st[u].size()) st[u].swap(st[v]);
        for (auto& P : st[v]) {
            /*P.ff + x - 2*dist[u] == k;*/
            /*x == k + 2*dist[u] - P.ff;*/
            ll x = k+2*dist[u]-P.ff;
            if (st[u].count(x)) {
                /*cout << st[u][x] + P.ss - 2*depth[u] << endl;*/
                setmin(ans, st[u][x] + P.ss - 2*depth[u]);
            }
        }
        for (auto& P : st[v]) {
            if (!st[u].count(P.ff)) st[u][P.ff] = P.ss;
            else setmin(st[u][P.ff], P.ss);
        }
    }
    /*cout << u << ": " << endl;*/
    /*for (auto& P : st[u]) {*/
        /*cout << "  " << P.ff-dist[u] << ", " << P.ss-depth[u] << endl;*/
        /*cout << "  " << P.ff << ", " << P.ss << endl;*/
    /*}*/
}

int best_path(int N, int K, int H[][2], int L[]) {
    n = N;
    k = K;
    gp = VVPI(n);
    rep(i, n-1) {
        int u = H[i][0];
        int v = H[i][1];
        int w = L[i];
        gp[u].pb({v, w});
        gp[v].pb({u, w});
    }
    dist = VL(n);
    depth = VI(n);
    dfs1();
    st = vector<map<ll, int>>(n);
    dfs2();
    if (ans == 2e9) return -1;
    return ans;
}


Compilation message

race.cpp: In function 'void dfs1(int, int)':
race.cpp:42:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   42 |     for (auto[v, w] : gp[u]) if (v != p) {
      |              ^
race.cpp: In function 'void dfs2(int, int)':
race.cpp:52:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   52 |     for (auto[v, w] : gp[u]) if (v != p) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 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 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 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 0 ms 2396 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 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 70 ms 32336 KB Output is correct
20 Correct 71 ms 33108 KB Output is correct
21 Correct 74 ms 32592 KB Output is correct
22 Correct 83 ms 32812 KB Output is correct
23 Correct 113 ms 45420 KB Output is correct
24 Correct 79 ms 36180 KB Output is correct
25 Correct 60 ms 32340 KB Output is correct
26 Correct 39 ms 38740 KB Output is correct
27 Correct 123 ms 49256 KB Output is correct
28 Correct 186 ms 85332 KB Output is correct
29 Correct 187 ms 84260 KB Output is correct
30 Correct 117 ms 49696 KB Output is correct
31 Correct 122 ms 49748 KB Output is correct
32 Correct 134 ms 49748 KB Output is correct
33 Correct 162 ms 54864 KB Output is correct
34 Correct 239 ms 87124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2396 KB Output is correct
2 Correct 1 ms 2396 KB Output is correct
3 Correct 0 ms 2396 KB Output is correct
4 Correct 0 ms 2396 KB Output is correct
5 Correct 0 ms 2396 KB Output is correct
6 Correct 0 ms 2396 KB Output is correct
7 Correct 0 ms 2396 KB Output is correct
8 Correct 0 ms 2396 KB Output is correct
9 Correct 1 ms 2396 KB Output is correct
10 Correct 0 ms 2396 KB Output is correct
11 Correct 0 ms 2396 KB Output is correct
12 Correct 0 ms 2396 KB Output is correct
13 Correct 0 ms 2396 KB Output is correct
14 Correct 0 ms 2396 KB Output is correct
15 Correct 1 ms 2396 KB Output is correct
16 Correct 0 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 0 ms 2396 KB Output is correct
21 Correct 1 ms 2652 KB Output is correct
22 Correct 2 ms 2652 KB Output is correct
23 Correct 1 ms 2652 KB Output is correct
24 Correct 1 ms 2652 KB Output is correct
25 Correct 1 ms 2652 KB Output is correct
26 Correct 1 ms 2652 KB Output is correct
27 Correct 1 ms 2496 KB Output is correct
28 Correct 1 ms 2652 KB Output is correct
29 Correct 1 ms 2652 KB Output is correct
30 Correct 1 ms 2652 KB Output is correct
31 Correct 1 ms 2652 KB Output is correct
32 Correct 1 ms 2652 KB Output is correct
33 Correct 1 ms 2652 KB Output is correct
34 Correct 1 ms 2652 KB Output is correct
35 Correct 1 ms 2652 KB Output is correct
36 Correct 1 ms 2652 KB Output is correct
37 Correct 1 ms 2652 KB Output is correct
38 Correct 1 ms 2652 KB Output is correct
39 Correct 70 ms 32336 KB Output is correct
40 Correct 71 ms 33108 KB Output is correct
41 Correct 74 ms 32592 KB Output is correct
42 Correct 83 ms 32812 KB Output is correct
43 Correct 113 ms 45420 KB Output is correct
44 Correct 79 ms 36180 KB Output is correct
45 Correct 60 ms 32340 KB Output is correct
46 Correct 39 ms 38740 KB Output is correct
47 Correct 123 ms 49256 KB Output is correct
48 Correct 186 ms 85332 KB Output is correct
49 Correct 187 ms 84260 KB Output is correct
50 Correct 117 ms 49696 KB Output is correct
51 Correct 122 ms 49748 KB Output is correct
52 Correct 134 ms 49748 KB Output is correct
53 Correct 162 ms 54864 KB Output is correct
54 Correct 239 ms 87124 KB Output is correct
55 Correct 11 ms 6352 KB Output is correct
56 Correct 6 ms 4796 KB Output is correct
57 Correct 43 ms 29776 KB Output is correct
58 Correct 33 ms 24016 KB Output is correct
59 Correct 67 ms 44924 KB Output is correct
60 Correct 179 ms 84500 KB Output is correct
61 Correct 185 ms 52564 KB Output is correct
62 Correct 172 ms 49964 KB Output is correct
63 Correct 165 ms 49768 KB Output is correct
64 Correct 347 ms 103452 KB Output is correct
65 Correct 322 ms 103252 KB Output is correct
66 Correct 208 ms 79132 KB Output is correct
67 Correct 98 ms 44996 KB Output is correct
68 Correct 269 ms 66132 KB Output is correct
69 Correct 273 ms 69120 KB Output is correct
70 Correct 227 ms 63860 KB Output is correct