Submission #419305

# Submission time Handle Problem Language Result Execution time Memory
419305 2021-06-06T19:58:59 Z iulia13 Race (IOI11_race) C++14
100 / 100
1664 ms 50184 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;
const int N = 2e5 + 5;
const int K = 1e6 + 5;
struct ura{
    int x, c;
};
vector <ura> g[N];
int vc[K];
int sz[N], viz[N];
int n, k; int minim = K;
void dfsSize(int nod, int dad = -1)
{
    sz[nod] = 1;
    for (auto son : g[nod])
    {
        if (son.x == dad || viz[son.x])
            continue;
        dfsSize(son.x, nod);
        sz[nod] += sz[son.x];
    }
}
map <int, int> mp2;
int centroid(int nod, int dad, int newN)
{
    for (auto son : g[nod])
    {
        if (son.x == dad || viz[son.x])
            continue;
        if (sz[son.x] > newN / 2)
            return centroid(son.x, nod, newN);
    }
    return nod;
}
void dfs(int nod, int dad, int sum, int l)
{
    if (sum > k)
        return;
    if (mp2[sum])
        mp2[sum] = min(mp2[sum], l);
    else
        mp2[sum] = l;
    for (auto son : g[nod])
    {
        if (son.x == dad || viz[son.x])
            continue;
        dfs(son.x, nod, sum + son.c, l + 1);
    }
}
void divide(int root)
{
    dfsSize(root);
    int mid = centroid(root, -1, sz[root]);
    viz[mid] = 1;
    map <int, int> mp;
    for (auto son : g[mid])
    {
        int x = son.x;
        if (viz[x])
            continue;
        mp2.clear();
        dfs(x, mid, son.c, 1);
        for (auto it : mp2)
        {
            if (it.first == k)
                minim = min(minim, it.second);
            if (mp.count(k - it.first) == 0)
                continue;
            minim = min(minim, it.second + mp[k - it.first]);
        }
        for (auto it : mp2)
        {
            int beb = it.first;
            if (mp[beb] == 0)
                mp[beb] = mp2[beb];
            else
                mp[beb] = min(mp[beb], mp2[beb]);
        }
    }
    for (auto son : g[mid])
        if (viz[son.x] == 0)
            divide(son.x);
}
int best_path(int nn, int kk, int h[][2], int l[])
{
    int i;
    n = nn;
    k = kk;
    for (i = 0; i < n - 1; i++)
    {
        int a = h[i][0];
        int b = h[i][1];
        g[a].push_back({b, l[i]});
        g[b].push_back({a, l[i]});
    }
    divide(0);
    if (minim == K)
        minim = -1;
    return minim;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 5000 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 5000 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5012 KB Output is correct
25 Correct 6 ms 5144 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 6 ms 5068 KB Output is correct
29 Correct 6 ms 5068 KB Output is correct
30 Correct 6 ms 5068 KB Output is correct
31 Correct 6 ms 5136 KB Output is correct
32 Correct 6 ms 5068 KB Output is correct
33 Correct 7 ms 5068 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 6 ms 5068 KB Output is correct
38 Correct 6 ms 5068 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 5000 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 277 ms 12168 KB Output is correct
20 Correct 286 ms 12064 KB Output is correct
21 Correct 272 ms 12028 KB Output is correct
22 Correct 251 ms 12124 KB Output is correct
23 Correct 104 ms 12228 KB Output is correct
24 Correct 124 ms 12204 KB Output is correct
25 Correct 167 ms 15644 KB Output is correct
26 Correct 110 ms 19140 KB Output is correct
27 Correct 263 ms 18308 KB Output is correct
28 Correct 356 ms 32712 KB Output is correct
29 Correct 332 ms 31440 KB Output is correct
30 Correct 272 ms 18376 KB Output is correct
31 Correct 270 ms 18316 KB Output is correct
32 Correct 278 ms 18372 KB Output is correct
33 Correct 492 ms 17184 KB Output is correct
34 Correct 192 ms 17220 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 5004 KB Output is correct
2 Correct 3 ms 5004 KB Output is correct
3 Correct 3 ms 4940 KB Output is correct
4 Correct 3 ms 4940 KB Output is correct
5 Correct 3 ms 4940 KB Output is correct
6 Correct 3 ms 4940 KB Output is correct
7 Correct 4 ms 4940 KB Output is correct
8 Correct 3 ms 5000 KB Output is correct
9 Correct 3 ms 4940 KB Output is correct
10 Correct 3 ms 4940 KB Output is correct
11 Correct 4 ms 4940 KB Output is correct
12 Correct 3 ms 4940 KB Output is correct
13 Correct 3 ms 4940 KB Output is correct
14 Correct 3 ms 5008 KB Output is correct
15 Correct 3 ms 4940 KB Output is correct
16 Correct 3 ms 5004 KB Output is correct
17 Correct 4 ms 4940 KB Output is correct
18 Correct 4 ms 4940 KB Output is correct
19 Correct 4 ms 4940 KB Output is correct
20 Correct 3 ms 4940 KB Output is correct
21 Correct 5 ms 5120 KB Output is correct
22 Correct 4 ms 5068 KB Output is correct
23 Correct 4 ms 5068 KB Output is correct
24 Correct 4 ms 5012 KB Output is correct
25 Correct 6 ms 5144 KB Output is correct
26 Correct 4 ms 5068 KB Output is correct
27 Correct 4 ms 5068 KB Output is correct
28 Correct 6 ms 5068 KB Output is correct
29 Correct 6 ms 5068 KB Output is correct
30 Correct 6 ms 5068 KB Output is correct
31 Correct 6 ms 5136 KB Output is correct
32 Correct 6 ms 5068 KB Output is correct
33 Correct 7 ms 5068 KB Output is correct
34 Correct 5 ms 5068 KB Output is correct
35 Correct 5 ms 5068 KB Output is correct
36 Correct 5 ms 5068 KB Output is correct
37 Correct 6 ms 5068 KB Output is correct
38 Correct 6 ms 5068 KB Output is correct
39 Correct 277 ms 12168 KB Output is correct
40 Correct 286 ms 12064 KB Output is correct
41 Correct 272 ms 12028 KB Output is correct
42 Correct 251 ms 12124 KB Output is correct
43 Correct 104 ms 12228 KB Output is correct
44 Correct 124 ms 12204 KB Output is correct
45 Correct 167 ms 15644 KB Output is correct
46 Correct 110 ms 19140 KB Output is correct
47 Correct 263 ms 18308 KB Output is correct
48 Correct 356 ms 32712 KB Output is correct
49 Correct 332 ms 31440 KB Output is correct
50 Correct 272 ms 18376 KB Output is correct
51 Correct 270 ms 18316 KB Output is correct
52 Correct 278 ms 18372 KB Output is correct
53 Correct 492 ms 17184 KB Output is correct
54 Correct 192 ms 17220 KB Output is correct
55 Correct 32 ms 6040 KB Output is correct
56 Correct 21 ms 5708 KB Output is correct
57 Correct 174 ms 12116 KB Output is correct
58 Correct 57 ms 11908 KB Output is correct
59 Correct 611 ms 26424 KB Output is correct
60 Correct 1664 ms 50184 KB Output is correct
61 Correct 399 ms 19776 KB Output is correct
62 Correct 446 ms 19780 KB Output is correct
63 Correct 517 ms 19672 KB Output is correct
64 Correct 1510 ms 30928 KB Output is correct
65 Correct 241 ms 20220 KB Output is correct
66 Correct 1101 ms 31844 KB Output is correct
67 Correct 169 ms 20148 KB Output is correct
68 Correct 602 ms 26948 KB Output is correct
69 Correct 610 ms 27328 KB Output is correct
70 Correct 540 ms 26512 KB Output is correct