Submission #900174

# Submission time Handle Problem Language Result Execution time Memory
900174 2024-01-07T20:09:59 Z subrat0018 Race (IOI11_race) C++17
100 / 100
249 ms 57024 KB
#include <bits/stdc++.h>
using namespace std;
#define nline "\n"
using uint = unsigned int;
const int M = 1e9 + 7;
const int M2 = 998244353;
const int INF = 1e9;
const int N = 1e6 + 10;
const double Degree = 57.2958;



int n,k;
int sz[N];
bool dead[N];
int dist[N];
vector<pair<int, int>> g[N];
vector<int> temp;
void prep(int v,int d, int len, int par = -1)
{
    if(len > k)return;
    dist[len] = min(dist[len], d);
    temp.push_back(len);
    for(auto &val:g[v])
    {
        if(val.first == par || dead[val.first])continue;
        prep(val.first, d + 1, len + val.second, v);
    }
}

int func(int v, int d, int len, int par = -1)
{
    if(len > k)return INF;
    int ans = d + dist[k - len];
    for(auto &val:g[v])
    {
        if(val.first == par || dead[val.first])continue;
        ans = min(ans, func(val.first, d + 1, len + val.second, v));
    }
    return ans;
}

void dfs(int v, int par=-1)
{
    sz[v] = 1;
    for(auto &val:g[v])
    {
        if(val.first != par && !dead[val.first])
        {
            dfs(val.first, v);
            sz[v] += sz[val.first];
        }
    }
}
int find_centroid(int currSize, int v, int par = -1)
{
    for(auto &val:g[v])
        if(val.first != par && !dead[val.first] && 2 * sz[val.first] > currSize)
            return find_centroid(currSize, val.first, v);
    return v;
}

int decompose(int v)
{
    dfs(v);
    int centorid = find_centroid(sz[v], v);
    dead[centorid] = true;
    
    int ans = INF;
    temp.clear();
    dist[0] = 0;
    for(auto &val:g[centorid])
    {
        if(!dead[val.first])
        {
            ans = min(func(val.first, 1, val.second, centorid), ans);
            prep(val.first, 1, val.second, centorid);
        }
    }
    dist[0] = INF;
    // set<int> st(temp.begin(),temp.end());
    // temp.clear();
    // temp.assign(st.begin(),st.end());
    for(auto &val:temp)
        dist[val] = INF;
    for(auto &val:g[centorid])
        if(!dead[val.first])
            ans = min(ans, decompose(val.first));
    return ans;
}
int best_path(int nn, int K, int H[][2], int* L)
{
    n = nn;
    k = K;
    vector<pair<int, int>> arr;
    for(int i=0;i<N;i++)
        dist[i] = INF;
    for(int i=0;i<n-1;i++)
    {
        int u,v;
        u = H[i][0];
        v = H[i][1];
        arr.push_back({u,v});
    }
    int ct = 0;
    for(auto &val:arr)
    {
        int w;
        w = L[ct++];
        g[val.first].push_back({val.second, w});
        g[val.second].push_back({val.first, w});
    }
    int ans = decompose(0);
    if(ans >= INF)
        return -1;
    else
        return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 7 ms 33284 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 7 ms 33208 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33268 KB Output is correct
8 Correct 6 ms 33112 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 7 ms 33112 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 6 ms 33244 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 6 ms 33280 KB Output is correct
15 Correct 6 ms 33244 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 6 ms 33116 KB Output is correct
18 Correct 7 ms 33116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 7 ms 33284 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 7 ms 33208 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33268 KB Output is correct
8 Correct 6 ms 33112 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 7 ms 33112 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 6 ms 33244 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 6 ms 33280 KB Output is correct
15 Correct 6 ms 33244 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 6 ms 33116 KB Output is correct
18 Correct 7 ms 33116 KB Output is correct
19 Correct 6 ms 33116 KB Output is correct
20 Correct 6 ms 33368 KB Output is correct
21 Correct 7 ms 33116 KB Output is correct
22 Correct 7 ms 33116 KB Output is correct
23 Correct 7 ms 33324 KB Output is correct
24 Correct 7 ms 33116 KB Output is correct
25 Correct 7 ms 33116 KB Output is correct
26 Correct 7 ms 33228 KB Output is correct
27 Correct 7 ms 33116 KB Output is correct
28 Correct 7 ms 33116 KB Output is correct
29 Correct 8 ms 33304 KB Output is correct
30 Correct 7 ms 33328 KB Output is correct
31 Correct 7 ms 33116 KB Output is correct
32 Correct 7 ms 33116 KB Output is correct
33 Correct 7 ms 33116 KB Output is correct
34 Correct 7 ms 33116 KB Output is correct
35 Correct 7 ms 33116 KB Output is correct
36 Correct 7 ms 33216 KB Output is correct
37 Correct 7 ms 33116 KB Output is correct
38 Correct 7 ms 33112 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 7 ms 33284 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 7 ms 33208 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33268 KB Output is correct
8 Correct 6 ms 33112 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 7 ms 33112 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 6 ms 33244 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 6 ms 33280 KB Output is correct
15 Correct 6 ms 33244 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 6 ms 33116 KB Output is correct
18 Correct 7 ms 33116 KB Output is correct
19 Correct 90 ms 40132 KB Output is correct
20 Correct 78 ms 39888 KB Output is correct
21 Correct 87 ms 40232 KB Output is correct
22 Correct 78 ms 40820 KB Output is correct
23 Correct 54 ms 40132 KB Output is correct
24 Correct 44 ms 39888 KB Output is correct
25 Correct 81 ms 42692 KB Output is correct
26 Correct 75 ms 46544 KB Output is correct
27 Correct 106 ms 44556 KB Output is correct
28 Correct 154 ms 55544 KB Output is correct
29 Correct 161 ms 54980 KB Output is correct
30 Correct 107 ms 44544 KB Output is correct
31 Correct 106 ms 44564 KB Output is correct
32 Correct 124 ms 44552 KB Output is correct
33 Correct 140 ms 43520 KB Output is correct
34 Correct 117 ms 43200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 33112 KB Output is correct
2 Correct 7 ms 33284 KB Output is correct
3 Correct 6 ms 33116 KB Output is correct
4 Correct 7 ms 33208 KB Output is correct
5 Correct 7 ms 33116 KB Output is correct
6 Correct 6 ms 33116 KB Output is correct
7 Correct 6 ms 33268 KB Output is correct
8 Correct 6 ms 33112 KB Output is correct
9 Correct 6 ms 33116 KB Output is correct
10 Correct 7 ms 33112 KB Output is correct
11 Correct 7 ms 33116 KB Output is correct
12 Correct 6 ms 33244 KB Output is correct
13 Correct 7 ms 33116 KB Output is correct
14 Correct 6 ms 33280 KB Output is correct
15 Correct 6 ms 33244 KB Output is correct
16 Correct 7 ms 33116 KB Output is correct
17 Correct 6 ms 33116 KB Output is correct
18 Correct 7 ms 33116 KB Output is correct
19 Correct 6 ms 33116 KB Output is correct
20 Correct 6 ms 33368 KB Output is correct
21 Correct 7 ms 33116 KB Output is correct
22 Correct 7 ms 33116 KB Output is correct
23 Correct 7 ms 33324 KB Output is correct
24 Correct 7 ms 33116 KB Output is correct
25 Correct 7 ms 33116 KB Output is correct
26 Correct 7 ms 33228 KB Output is correct
27 Correct 7 ms 33116 KB Output is correct
28 Correct 7 ms 33116 KB Output is correct
29 Correct 8 ms 33304 KB Output is correct
30 Correct 7 ms 33328 KB Output is correct
31 Correct 7 ms 33116 KB Output is correct
32 Correct 7 ms 33116 KB Output is correct
33 Correct 7 ms 33116 KB Output is correct
34 Correct 7 ms 33116 KB Output is correct
35 Correct 7 ms 33116 KB Output is correct
36 Correct 7 ms 33216 KB Output is correct
37 Correct 7 ms 33116 KB Output is correct
38 Correct 7 ms 33112 KB Output is correct
39 Correct 90 ms 40132 KB Output is correct
40 Correct 78 ms 39888 KB Output is correct
41 Correct 87 ms 40232 KB Output is correct
42 Correct 78 ms 40820 KB Output is correct
43 Correct 54 ms 40132 KB Output is correct
44 Correct 44 ms 39888 KB Output is correct
45 Correct 81 ms 42692 KB Output is correct
46 Correct 75 ms 46544 KB Output is correct
47 Correct 106 ms 44556 KB Output is correct
48 Correct 154 ms 55544 KB Output is correct
49 Correct 161 ms 54980 KB Output is correct
50 Correct 107 ms 44544 KB Output is correct
51 Correct 106 ms 44564 KB Output is correct
52 Correct 124 ms 44552 KB Output is correct
53 Correct 140 ms 43520 KB Output is correct
54 Correct 117 ms 43200 KB Output is correct
55 Correct 12 ms 33624 KB Output is correct
56 Correct 13 ms 33804 KB Output is correct
57 Correct 58 ms 40976 KB Output is correct
58 Correct 33 ms 40912 KB Output is correct
59 Correct 75 ms 46408 KB Output is correct
60 Correct 249 ms 57024 KB Output is correct
61 Correct 116 ms 44992 KB Output is correct
62 Correct 126 ms 46272 KB Output is correct
63 Correct 163 ms 46524 KB Output is correct
64 Correct 249 ms 46016 KB Output is correct
65 Correct 116 ms 44484 KB Output is correct
66 Correct 223 ms 52820 KB Output is correct
67 Correct 75 ms 46604 KB Output is correct
68 Correct 146 ms 45504 KB Output is correct
69 Correct 135 ms 45504 KB Output is correct
70 Correct 129 ms 45064 KB Output is correct