Submission #146690

# Submission time Handle Problem Language Result Execution time Memory
146690 2019-08-25T08:14:47 Z karma Race (IOI11_race) C++11
100 / 100
1231 ms 159896 KB
#include <bits/stdc++.h>
#include "race.h"
#define Task     "test"
#define ll        long long
#define pb        emplace_back
#define mp        make_pair
#define fi        first
#define se        second

using namespace std;

typedef pair<ll, ll> pii;
const int N = int(2e5) + 7;

map<ll, int>* s[N];
int n, k, u, v, w, res, p[N], sz[N], h[N];
ll d[N];
vector<pii> a[N];

//void Insert(int root, ll d, int _h)
//{
//     pii found = *(s[root] -> lower_bound(mp(d, h[root])));
//     if(found.fi == d) _h = min((ll)_h, found.se), s[root] -> erase(found);
//     s[root] -> insert(mp(d, _h));
//}

void query(int u, int root)
{
    ll dis = 2ll * d[root] + k - d[u];
    //pii found = *(s[root] -> lower_bound(mp(dis, h[root])));
    int& hi = (*s[root])[dis];
    if(hi + h[u] - 2 * h[root] < res && hi) res = hi + h[u] - 2 * h[root];
    for(pii adj: a[u])
        if(adj.fi != p[u]) query(adj.fi, root);
}

void add(int u, int root)
{
    int& hi = (*s[root])[d[u]];
    if(!hi) hi = h[u];
    else hi = min(hi, h[u]);
    for(pii adj: a[u])
        if(adj.fi != p[u]) add(adj.fi, root);
}

void DSU(int u)
{
     int bigC = -1; sz[u] = 1;
     for(pii adj: a[u]) {
        if(adj.fi == p[u]) continue;
        d[adj.fi] = d[u] + adj.se;
        h[adj.fi] = h[u] + 1, p[adj.fi] = u;
        DSU(adj.fi); sz[u] += sz[adj.fi];
        if(bigC == -1 || sz[adj.fi] > sz[bigC]) bigC = adj.fi;
     }
     if(bigC != -1) s[u] = s[bigC];
     else s[u] = new map<ll, int>();
     int& hi = (*s[u])[d[u] + k];
     if(hi) res = min(res, hi - h[u]);
     int& irene = (*s[u])[d[u]];
     if(!irene) irene = h[u];
     else irene = min(irene, h[u]);
     for(pii adj: a[u]) {
        if(bigC == adj.fi || adj.fi == p[u]) continue;
        query(adj.fi, u), add(adj.fi, u);
     }
}

int best_path(int _n, int _k, int _h[][2], int _l[])
{
    n = _n, k = _k;
    for(int i = 0, lim = n - 1; i < lim; ++i) {
       a[_h[i][0]].pb(_h[i][1], _l[i]), a[_h[i][1]].pb(_h[i][0], _l[i]);
    }
    res = n + 1; h[0] = p[0] = d[0] = 0;
    DSU(0);
    if(res == n + 1) return -1;
    return res;
}

//int _h[N][2], _n, _k, _l[N];
//
//int main()
//{
//    ios_base::sync_with_stdio(0);
//    cin.tie(0), cout.tie(0);
//    if(fopen(Task".inp", "r")) {
//        freopen(Task".inp", "r", stdin);
//        freopen(Task".out", "w", stdout);
//    }
//
//    cin >> _n >> _k;
//    for(int i = 0; i < _n - 1; ++i) {
//        cin >> _h[i][0] >> _h[i][1] >> _l[i];
//    }
//    cout << best_path(_n, _k, _h, _l);
//
//    return 0;
//}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5116 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 6 ms 5116 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5116 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 6 ms 5116 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 4984 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 8 ms 5500 KB Output is correct
22 Correct 8 ms 5624 KB Output is correct
23 Correct 8 ms 5496 KB Output is correct
24 Correct 7 ms 5624 KB Output is correct
25 Correct 8 ms 5624 KB Output is correct
26 Correct 8 ms 5624 KB Output is correct
27 Correct 7 ms 5372 KB Output is correct
28 Correct 8 ms 5496 KB Output is correct
29 Correct 8 ms 5628 KB Output is correct
30 Correct 8 ms 5624 KB Output is correct
31 Correct 8 ms 5628 KB Output is correct
32 Correct 8 ms 5500 KB Output is correct
33 Correct 8 ms 5624 KB Output is correct
34 Correct 7 ms 5496 KB Output is correct
35 Correct 7 ms 5368 KB Output is correct
36 Correct 7 ms 5368 KB Output is correct
37 Correct 8 ms 5300 KB Output is correct
38 Correct 7 ms 5424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5116 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 6 ms 5116 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 242 ms 39004 KB Output is correct
20 Correct 242 ms 39032 KB Output is correct
21 Correct 240 ms 39388 KB Output is correct
22 Correct 262 ms 39684 KB Output is correct
23 Correct 354 ms 67268 KB Output is correct
24 Correct 276 ms 52492 KB Output is correct
25 Correct 170 ms 20552 KB Output is correct
26 Correct 73 ms 24696 KB Output is correct
27 Correct 313 ms 54208 KB Output is correct
28 Correct 307 ms 69268 KB Output is correct
29 Correct 345 ms 69428 KB Output is correct
30 Correct 306 ms 54352 KB Output is correct
31 Correct 291 ms 54232 KB Output is correct
32 Correct 390 ms 55416 KB Output is correct
33 Correct 399 ms 40568 KB Output is correct
34 Correct 869 ms 111408 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 5112 KB Output is correct
2 Correct 6 ms 5112 KB Output is correct
3 Correct 6 ms 5112 KB Output is correct
4 Correct 6 ms 5112 KB Output is correct
5 Correct 6 ms 5112 KB Output is correct
6 Correct 6 ms 5116 KB Output is correct
7 Correct 6 ms 5112 KB Output is correct
8 Correct 6 ms 5112 KB Output is correct
9 Correct 6 ms 5112 KB Output is correct
10 Correct 6 ms 5112 KB Output is correct
11 Correct 6 ms 5112 KB Output is correct
12 Correct 6 ms 5112 KB Output is correct
13 Correct 6 ms 5112 KB Output is correct
14 Correct 6 ms 5112 KB Output is correct
15 Correct 6 ms 5112 KB Output is correct
16 Correct 6 ms 5116 KB Output is correct
17 Correct 6 ms 5112 KB Output is correct
18 Correct 6 ms 5112 KB Output is correct
19 Correct 6 ms 4984 KB Output is correct
20 Correct 6 ms 5112 KB Output is correct
21 Correct 8 ms 5500 KB Output is correct
22 Correct 8 ms 5624 KB Output is correct
23 Correct 8 ms 5496 KB Output is correct
24 Correct 7 ms 5624 KB Output is correct
25 Correct 8 ms 5624 KB Output is correct
26 Correct 8 ms 5624 KB Output is correct
27 Correct 7 ms 5372 KB Output is correct
28 Correct 8 ms 5496 KB Output is correct
29 Correct 8 ms 5628 KB Output is correct
30 Correct 8 ms 5624 KB Output is correct
31 Correct 8 ms 5628 KB Output is correct
32 Correct 8 ms 5500 KB Output is correct
33 Correct 8 ms 5624 KB Output is correct
34 Correct 7 ms 5496 KB Output is correct
35 Correct 7 ms 5368 KB Output is correct
36 Correct 7 ms 5368 KB Output is correct
37 Correct 8 ms 5300 KB Output is correct
38 Correct 7 ms 5424 KB Output is correct
39 Correct 242 ms 39004 KB Output is correct
40 Correct 242 ms 39032 KB Output is correct
41 Correct 240 ms 39388 KB Output is correct
42 Correct 262 ms 39684 KB Output is correct
43 Correct 354 ms 67268 KB Output is correct
44 Correct 276 ms 52492 KB Output is correct
45 Correct 170 ms 20552 KB Output is correct
46 Correct 73 ms 24696 KB Output is correct
47 Correct 313 ms 54208 KB Output is correct
48 Correct 307 ms 69268 KB Output is correct
49 Correct 345 ms 69428 KB Output is correct
50 Correct 306 ms 54352 KB Output is correct
51 Correct 291 ms 54232 KB Output is correct
52 Correct 390 ms 55416 KB Output is correct
53 Correct 399 ms 40568 KB Output is correct
54 Correct 869 ms 111408 KB Output is correct
55 Correct 28 ms 10360 KB Output is correct
56 Correct 20 ms 8056 KB Output is correct
57 Correct 165 ms 39688 KB Output is correct
58 Correct 82 ms 32484 KB Output is correct
59 Correct 143 ms 38224 KB Output is correct
60 Correct 480 ms 71788 KB Output is correct
61 Correct 403 ms 64884 KB Output is correct
62 Correct 314 ms 58360 KB Output is correct
63 Correct 418 ms 58328 KB Output is correct
64 Correct 1231 ms 159808 KB Output is correct
65 Correct 1097 ms 159896 KB Output is correct
66 Correct 419 ms 73184 KB Output is correct
67 Correct 310 ms 63132 KB Output is correct
68 Correct 695 ms 95824 KB Output is correct
69 Correct 625 ms 97208 KB Output is correct
70 Correct 633 ms 92124 KB Output is correct