Submission #930906

# Submission time Handle Problem Language Result Execution time Memory
930906 2024-02-20T16:51:38 Z Art_ogo Race (IOI11_race) C++17
100 / 100
713 ms 82740 KB
#include <bits/stdc++.h>
#include "race.h"
 
#define ll long long
#define ve vector
#define fi first
#define se second
 
using namespace std;
 
const int MAXN = 1e6+10;
 
typedef pair<ll, ll> pll;
 
ve<pll> g[MAXN];
int sz[MAXN];
bool del[MAXN];
ve<pll> comp;
ll k;
 
void updsz(int v, int p){
    sz[v] = 1;
    for(auto& to : g[v])
        if(to.fi != p && !del[to.fi]){
            updsz(to.fi, v);
            sz[v] += sz[to.fi];
        }
}
 
int centroid(int v, int p, int ssz){
    for(auto& to : g[v])
        if(to.fi != p && !del[to.fi] && 2*sz[to.fi] > ssz)
            return centroid(to.fi, v, ssz);
    return v;
}
 
struct vertex{
    int sum, len, id;
};
 
void add(int v, int p, int len, int sum){
    comp.push_back({sum, len});
    for(auto& to : g[v])
        if(to.fi != p && !del[to.fi])
            add(to.fi, v, len + 1, to.se + sum);
}
 
int decomp(int v){
    updsz(v, v);
    int ssz = sz[v];
    int res = 1e9;
    v = centroid(v, v, ssz);
    del[v] = 1;
 
    map<ll, int> mp;
    mp[0] = 0;
    for(auto to : g[v]){
        if(!del[to.fi]){
            comp.clear();
            add(to.fi, v, 1, to.se);
            for(auto i : comp)
                if(mp.find(k - i.fi) != mp.end())
                    res = min<int>(res, mp[k - i.fi] + i.se);
            for(auto i : comp)
                if(mp.find(i.fi) == mp.end() || mp[i.fi] > i.se)
                    mp[i.fi] = i.se;
        }
    }
    for(auto to : g[v])
        if(!del[to.fi])
            res = min(res, decomp(to.fi));
    return res;
}
 
 
int best_path(int N, int K, int H[][2], int L[])
{
    k = K;
    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 res = decomp(0);
    if(res == 1e9)
        return -1;
    return res;
}
 
# Verdict Execution time Memory Grader output
1 Correct 8 ms 30296 KB Output is correct
2 Correct 7 ms 30300 KB Output is correct
3 Correct 7 ms 30416 KB Output is correct
4 Correct 7 ms 30300 KB Output is correct
5 Correct 7 ms 30300 KB Output is correct
6 Correct 8 ms 30392 KB Output is correct
7 Correct 7 ms 30300 KB Output is correct
8 Correct 7 ms 30384 KB Output is correct
9 Correct 8 ms 30300 KB Output is correct
10 Correct 6 ms 30420 KB Output is correct
11 Correct 7 ms 30300 KB Output is correct
12 Correct 7 ms 30300 KB Output is correct
13 Correct 7 ms 30300 KB Output is correct
14 Correct 7 ms 30200 KB Output is correct
15 Correct 7 ms 30296 KB Output is correct
16 Correct 7 ms 30300 KB Output is correct
17 Correct 9 ms 30300 KB Output is correct
18 Correct 8 ms 30304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 30296 KB Output is correct
2 Correct 7 ms 30300 KB Output is correct
3 Correct 7 ms 30416 KB Output is correct
4 Correct 7 ms 30300 KB Output is correct
5 Correct 7 ms 30300 KB Output is correct
6 Correct 8 ms 30392 KB Output is correct
7 Correct 7 ms 30300 KB Output is correct
8 Correct 7 ms 30384 KB Output is correct
9 Correct 8 ms 30300 KB Output is correct
10 Correct 6 ms 30420 KB Output is correct
11 Correct 7 ms 30300 KB Output is correct
12 Correct 7 ms 30300 KB Output is correct
13 Correct 7 ms 30300 KB Output is correct
14 Correct 7 ms 30200 KB Output is correct
15 Correct 7 ms 30296 KB Output is correct
16 Correct 7 ms 30300 KB Output is correct
17 Correct 9 ms 30300 KB Output is correct
18 Correct 8 ms 30304 KB Output is correct
19 Correct 7 ms 30296 KB Output is correct
20 Correct 8 ms 30300 KB Output is correct
21 Correct 8 ms 30300 KB Output is correct
22 Correct 8 ms 30556 KB Output is correct
23 Correct 8 ms 30552 KB Output is correct
24 Correct 8 ms 30556 KB Output is correct
25 Correct 8 ms 30556 KB Output is correct
26 Correct 8 ms 30556 KB Output is correct
27 Correct 8 ms 30300 KB Output is correct
28 Correct 8 ms 30556 KB Output is correct
29 Correct 8 ms 30552 KB Output is correct
30 Correct 8 ms 30552 KB Output is correct
31 Correct 8 ms 30556 KB Output is correct
32 Correct 8 ms 30556 KB Output is correct
33 Correct 8 ms 30580 KB Output is correct
34 Correct 8 ms 30556 KB Output is correct
35 Correct 8 ms 30556 KB Output is correct
36 Correct 8 ms 30556 KB Output is correct
37 Correct 9 ms 30812 KB Output is correct
38 Correct 8 ms 30552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 30296 KB Output is correct
2 Correct 7 ms 30300 KB Output is correct
3 Correct 7 ms 30416 KB Output is correct
4 Correct 7 ms 30300 KB Output is correct
5 Correct 7 ms 30300 KB Output is correct
6 Correct 8 ms 30392 KB Output is correct
7 Correct 7 ms 30300 KB Output is correct
8 Correct 7 ms 30384 KB Output is correct
9 Correct 8 ms 30300 KB Output is correct
10 Correct 6 ms 30420 KB Output is correct
11 Correct 7 ms 30300 KB Output is correct
12 Correct 7 ms 30300 KB Output is correct
13 Correct 7 ms 30300 KB Output is correct
14 Correct 7 ms 30200 KB Output is correct
15 Correct 7 ms 30296 KB Output is correct
16 Correct 7 ms 30300 KB Output is correct
17 Correct 9 ms 30300 KB Output is correct
18 Correct 8 ms 30304 KB Output is correct
19 Correct 156 ms 38628 KB Output is correct
20 Correct 159 ms 38864 KB Output is correct
21 Correct 163 ms 38864 KB Output is correct
22 Correct 146 ms 38864 KB Output is correct
23 Correct 216 ms 39112 KB Output is correct
24 Correct 102 ms 37852 KB Output is correct
25 Correct 153 ms 43480 KB Output is correct
26 Correct 85 ms 44496 KB Output is correct
27 Correct 248 ms 43600 KB Output is correct
28 Correct 640 ms 82740 KB Output is correct
29 Correct 681 ms 82008 KB Output is correct
30 Correct 212 ms 45648 KB Output is correct
31 Correct 229 ms 46068 KB Output is correct
32 Correct 230 ms 45648 KB Output is correct
33 Correct 307 ms 46540 KB Output is correct
34 Correct 588 ms 67788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 30296 KB Output is correct
2 Correct 7 ms 30300 KB Output is correct
3 Correct 7 ms 30416 KB Output is correct
4 Correct 7 ms 30300 KB Output is correct
5 Correct 7 ms 30300 KB Output is correct
6 Correct 8 ms 30392 KB Output is correct
7 Correct 7 ms 30300 KB Output is correct
8 Correct 7 ms 30384 KB Output is correct
9 Correct 8 ms 30300 KB Output is correct
10 Correct 6 ms 30420 KB Output is correct
11 Correct 7 ms 30300 KB Output is correct
12 Correct 7 ms 30300 KB Output is correct
13 Correct 7 ms 30300 KB Output is correct
14 Correct 7 ms 30200 KB Output is correct
15 Correct 7 ms 30296 KB Output is correct
16 Correct 7 ms 30300 KB Output is correct
17 Correct 9 ms 30300 KB Output is correct
18 Correct 8 ms 30304 KB Output is correct
19 Correct 7 ms 30296 KB Output is correct
20 Correct 8 ms 30300 KB Output is correct
21 Correct 8 ms 30300 KB Output is correct
22 Correct 8 ms 30556 KB Output is correct
23 Correct 8 ms 30552 KB Output is correct
24 Correct 8 ms 30556 KB Output is correct
25 Correct 8 ms 30556 KB Output is correct
26 Correct 8 ms 30556 KB Output is correct
27 Correct 8 ms 30300 KB Output is correct
28 Correct 8 ms 30556 KB Output is correct
29 Correct 8 ms 30552 KB Output is correct
30 Correct 8 ms 30552 KB Output is correct
31 Correct 8 ms 30556 KB Output is correct
32 Correct 8 ms 30556 KB Output is correct
33 Correct 8 ms 30580 KB Output is correct
34 Correct 8 ms 30556 KB Output is correct
35 Correct 8 ms 30556 KB Output is correct
36 Correct 8 ms 30556 KB Output is correct
37 Correct 9 ms 30812 KB Output is correct
38 Correct 8 ms 30552 KB Output is correct
39 Correct 156 ms 38628 KB Output is correct
40 Correct 159 ms 38864 KB Output is correct
41 Correct 163 ms 38864 KB Output is correct
42 Correct 146 ms 38864 KB Output is correct
43 Correct 216 ms 39112 KB Output is correct
44 Correct 102 ms 37852 KB Output is correct
45 Correct 153 ms 43480 KB Output is correct
46 Correct 85 ms 44496 KB Output is correct
47 Correct 248 ms 43600 KB Output is correct
48 Correct 640 ms 82740 KB Output is correct
49 Correct 681 ms 82008 KB Output is correct
50 Correct 212 ms 45648 KB Output is correct
51 Correct 229 ms 46068 KB Output is correct
52 Correct 230 ms 45648 KB Output is correct
53 Correct 307 ms 46540 KB Output is correct
54 Correct 588 ms 67788 KB Output is correct
55 Correct 24 ms 31832 KB Output is correct
56 Correct 16 ms 31068 KB Output is correct
57 Correct 115 ms 39532 KB Output is correct
58 Correct 44 ms 38132 KB Output is correct
59 Correct 265 ms 54476 KB Output is correct
60 Correct 713 ms 80208 KB Output is correct
61 Correct 255 ms 46672 KB Output is correct
62 Correct 235 ms 45736 KB Output is correct
63 Correct 232 ms 45648 KB Output is correct
64 Correct 703 ms 60008 KB Output is correct
65 Correct 587 ms 69312 KB Output is correct
66 Correct 653 ms 78268 KB Output is correct
67 Correct 96 ms 45504 KB Output is correct
68 Correct 339 ms 62312 KB Output is correct
69 Correct 330 ms 60640 KB Output is correct
70 Correct 318 ms 61444 KB Output is correct