Submission #1118473

# Submission time Handle Problem Language Result Execution time Memory
1118473 2024-11-25T14:17:49 Z alexdd Race (IOI11_race) C++17
100 / 100
1885 ms 148972 KB
#include "race.h"
#include<bits/stdc++.h>
using namespace std;
const int INF = 1e8;
int rez;
long long K;
vector<pair<int,int>> con[200005];
unordered_map<long long,int> dp[200005];
int d[200005];
long long d2[200005];
void dfs(int nod, int par)
{
    if(d2[nod]==K) rez = min(rez, d[nod]);
    int maxc=-1,heavy=-1;
    for(auto [adj,w]:con[nod])
    {
        if(adj==par)
            continue;
        d[adj] = d[nod] + 1;
        d2[adj] = d2[nod] + w;
        dfs(adj,nod);
        if((int)dp[adj].size() > maxc)
            maxc = dp[adj].size(), heavy=adj;
    }
    if(heavy==-1)
    {

    }
    else
    {
        swap(dp[nod], dp[heavy]);
        for(auto [adj,w]:con[nod])
        {
            if(adj==par || adj==heavy)
                continue;
            for(auto it:dp[adj])
            {
                rez = min(rez, it.second + dp[nod][K+2*d2[nod]-it.first] + 2*INF - 2*d[nod]);
                ///it.first + x - 2*d2[nod] = K
            }
            for(auto it:dp[adj])
                if(it.first - d2[nod] <= K)
                    dp[nod][it.first] = min(dp[nod][it.first], it.second);
            dp[adj].clear();
        }
    }
    rez = min(rez, dp[nod][K+d2[nod]] + INF - d[nod]);
    ///x - d2[nod] = K
    dp[nod][d2[nod]] = min(dp[nod][d2[nod]], d[nod] - INF);
}
int best_path(int N, int copK, int H[][2], int L[])
{
    K = copK;
    rez = N+2;
    for(int i=0;i<N-1;i++)
    {
        con[H[i][0]].push_back({H[i][1],L[i]});
        con[H[i][1]].push_back({H[i][0],L[i]});
    }
    dfs(0,-1);
    if(rez==N+2)
        rez=-1;
    return rez;
}
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22116 KB Output is correct
2 Correct 5 ms 22096 KB Output is correct
3 Correct 13 ms 18000 KB Output is correct
4 Correct 13 ms 18012 KB Output is correct
5 Correct 14 ms 15976 KB Output is correct
6 Correct 16 ms 15956 KB Output is correct
7 Correct 12 ms 15964 KB Output is correct
8 Correct 13 ms 16164 KB Output is correct
9 Correct 12 ms 15964 KB Output is correct
10 Correct 5 ms 22108 KB Output is correct
11 Correct 6 ms 22108 KB Output is correct
12 Correct 5 ms 22108 KB Output is correct
13 Correct 7 ms 22112 KB Output is correct
14 Correct 7 ms 22108 KB Output is correct
15 Correct 6 ms 22112 KB Output is correct
16 Correct 5 ms 22096 KB Output is correct
17 Correct 7 ms 22096 KB Output is correct
18 Correct 8 ms 22116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22116 KB Output is correct
2 Correct 5 ms 22096 KB Output is correct
3 Correct 13 ms 18000 KB Output is correct
4 Correct 13 ms 18012 KB Output is correct
5 Correct 14 ms 15976 KB Output is correct
6 Correct 16 ms 15956 KB Output is correct
7 Correct 12 ms 15964 KB Output is correct
8 Correct 13 ms 16164 KB Output is correct
9 Correct 12 ms 15964 KB Output is correct
10 Correct 5 ms 22108 KB Output is correct
11 Correct 6 ms 22108 KB Output is correct
12 Correct 5 ms 22108 KB Output is correct
13 Correct 7 ms 22112 KB Output is correct
14 Correct 7 ms 22108 KB Output is correct
15 Correct 6 ms 22112 KB Output is correct
16 Correct 5 ms 22096 KB Output is correct
17 Correct 7 ms 22096 KB Output is correct
18 Correct 8 ms 22116 KB Output is correct
19 Correct 5 ms 21840 KB Output is correct
20 Correct 8 ms 18000 KB Output is correct
21 Correct 13 ms 16208 KB Output is correct
22 Correct 14 ms 16216 KB Output is correct
23 Correct 14 ms 20512 KB Output is correct
24 Correct 13 ms 16464 KB Output is correct
25 Correct 13 ms 16448 KB Output is correct
26 Correct 20 ms 16464 KB Output is correct
27 Correct 12 ms 16228 KB Output is correct
28 Correct 15 ms 16464 KB Output is correct
29 Correct 15 ms 16464 KB Output is correct
30 Correct 14 ms 16476 KB Output is correct
31 Correct 13 ms 16464 KB Output is correct
32 Correct 18 ms 16456 KB Output is correct
33 Correct 16 ms 16744 KB Output is correct
34 Correct 12 ms 16220 KB Output is correct
35 Correct 12 ms 16220 KB Output is correct
36 Correct 17 ms 16208 KB Output is correct
37 Correct 7 ms 22108 KB Output is correct
38 Correct 8 ms 22108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22116 KB Output is correct
2 Correct 5 ms 22096 KB Output is correct
3 Correct 13 ms 18000 KB Output is correct
4 Correct 13 ms 18012 KB Output is correct
5 Correct 14 ms 15976 KB Output is correct
6 Correct 16 ms 15956 KB Output is correct
7 Correct 12 ms 15964 KB Output is correct
8 Correct 13 ms 16164 KB Output is correct
9 Correct 12 ms 15964 KB Output is correct
10 Correct 5 ms 22108 KB Output is correct
11 Correct 6 ms 22108 KB Output is correct
12 Correct 5 ms 22108 KB Output is correct
13 Correct 7 ms 22112 KB Output is correct
14 Correct 7 ms 22108 KB Output is correct
15 Correct 6 ms 22112 KB Output is correct
16 Correct 5 ms 22096 KB Output is correct
17 Correct 7 ms 22096 KB Output is correct
18 Correct 8 ms 22116 KB Output is correct
19 Correct 138 ms 35712 KB Output is correct
20 Correct 120 ms 35568 KB Output is correct
21 Correct 102 ms 36160 KB Output is correct
22 Correct 113 ms 30536 KB Output is correct
23 Correct 201 ms 39496 KB Output is correct
24 Correct 141 ms 36980 KB Output is correct
25 Correct 79 ms 30804 KB Output is correct
26 Correct 72 ms 38724 KB Output is correct
27 Correct 219 ms 47920 KB Output is correct
28 Correct 288 ms 81008 KB Output is correct
29 Correct 275 ms 81008 KB Output is correct
30 Correct 203 ms 50732 KB Output is correct
31 Correct 210 ms 47176 KB Output is correct
32 Correct 236 ms 48144 KB Output is correct
33 Correct 133 ms 32328 KB Output is correct
34 Correct 574 ms 82552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 22116 KB Output is correct
2 Correct 5 ms 22096 KB Output is correct
3 Correct 13 ms 18000 KB Output is correct
4 Correct 13 ms 18012 KB Output is correct
5 Correct 14 ms 15976 KB Output is correct
6 Correct 16 ms 15956 KB Output is correct
7 Correct 12 ms 15964 KB Output is correct
8 Correct 13 ms 16164 KB Output is correct
9 Correct 12 ms 15964 KB Output is correct
10 Correct 5 ms 22108 KB Output is correct
11 Correct 6 ms 22108 KB Output is correct
12 Correct 5 ms 22108 KB Output is correct
13 Correct 7 ms 22112 KB Output is correct
14 Correct 7 ms 22108 KB Output is correct
15 Correct 6 ms 22112 KB Output is correct
16 Correct 5 ms 22096 KB Output is correct
17 Correct 7 ms 22096 KB Output is correct
18 Correct 8 ms 22116 KB Output is correct
19 Correct 5 ms 21840 KB Output is correct
20 Correct 8 ms 18000 KB Output is correct
21 Correct 13 ms 16208 KB Output is correct
22 Correct 14 ms 16216 KB Output is correct
23 Correct 14 ms 20512 KB Output is correct
24 Correct 13 ms 16464 KB Output is correct
25 Correct 13 ms 16448 KB Output is correct
26 Correct 20 ms 16464 KB Output is correct
27 Correct 12 ms 16228 KB Output is correct
28 Correct 15 ms 16464 KB Output is correct
29 Correct 15 ms 16464 KB Output is correct
30 Correct 14 ms 16476 KB Output is correct
31 Correct 13 ms 16464 KB Output is correct
32 Correct 18 ms 16456 KB Output is correct
33 Correct 16 ms 16744 KB Output is correct
34 Correct 12 ms 16220 KB Output is correct
35 Correct 12 ms 16220 KB Output is correct
36 Correct 17 ms 16208 KB Output is correct
37 Correct 7 ms 22108 KB Output is correct
38 Correct 8 ms 22108 KB Output is correct
39 Correct 138 ms 35712 KB Output is correct
40 Correct 120 ms 35568 KB Output is correct
41 Correct 102 ms 36160 KB Output is correct
42 Correct 113 ms 30536 KB Output is correct
43 Correct 201 ms 39496 KB Output is correct
44 Correct 141 ms 36980 KB Output is correct
45 Correct 79 ms 30804 KB Output is correct
46 Correct 72 ms 38724 KB Output is correct
47 Correct 219 ms 47920 KB Output is correct
48 Correct 288 ms 81008 KB Output is correct
49 Correct 275 ms 81008 KB Output is correct
50 Correct 203 ms 50732 KB Output is correct
51 Correct 210 ms 47176 KB Output is correct
52 Correct 236 ms 48144 KB Output is correct
53 Correct 133 ms 32328 KB Output is correct
54 Correct 574 ms 82552 KB Output is correct
55 Correct 22 ms 24664 KB Output is correct
56 Correct 12 ms 23140 KB Output is correct
57 Correct 73 ms 35752 KB Output is correct
58 Correct 68 ms 45336 KB Output is correct
59 Correct 66 ms 52924 KB Output is correct
60 Correct 241 ms 77424 KB Output is correct
61 Correct 237 ms 52296 KB Output is correct
62 Correct 301 ms 51104 KB Output is correct
63 Correct 260 ms 49256 KB Output is correct
64 Correct 1885 ms 148972 KB Output is correct
65 Correct 1002 ms 109804 KB Output is correct
66 Correct 321 ms 81012 KB Output is correct
67 Correct 268 ms 66344 KB Output is correct
68 Correct 736 ms 93264 KB Output is correct
69 Correct 764 ms 94392 KB Output is correct
70 Correct 681 ms 94840 KB Output is correct