Submission #964086

# Submission time Handle Problem Language Result Execution time Memory
964086 2024-04-16T09:56:44 Z maxFedorchuk Race (IOI11_race) C++17
100 / 100
364 ms 115376 KB
#include <bits/stdc++.h>
#include "race.h"
using namespace std;

const long long MX=2e5+10;
const long long INF=1e18;

vector < pair < long long , long long > > mas[MX];
set < pair < long long , long long > > st[MX];
long long dep[MX],vid[MX],ans=INF,kk;

void DFS(long long zar,long long mun)
{
    st[zar].insert({vid[zar],dep[zar]});

    for(auto [nxt,ds]:mas[zar])
    {
        if(nxt==mun)
        {
            continue;
        }

        vid[nxt]=vid[zar]+ds;
        dep[nxt]=dep[zar]+1;
        DFS(nxt,zar);

        if(st[zar].size()<st[nxt].size())
        {
            swap(st[zar],st[nxt]);
        }

        for(auto [rz,gl]:st[nxt])
        {
            auto it=st[zar].lower_bound({(kk+2*vid[zar])-rz,0});

            if(it!=st[zar].end())
            {
                if((*it).first+rz==kk+2*vid[zar])
                {
                    ans=min(ans,gl+(*it).second-2*dep[zar]);
                }
            }
        }

        for(auto u:st[nxt])
        {
            st[zar].insert(u);
        }
    }
}

int best_path(int N, int K, int H[][2], int L[]) 
{
    kk=K;

    for(long long i=0;i<N-1;i++)
    {
        mas[H[i][0]].push_back({H[i][1],L[i]});
        mas[H[i][1]].push_back({H[i][0],L[i]});
    }

    vid[0]=0;
    dep[0]=0;
    DFS(0,0);

    return ((ans==INF)?-1:ans);
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21296 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21340 KB Output is correct
9 Correct 4 ms 21340 KB Output is correct
10 Correct 5 ms 21284 KB Output is correct
11 Correct 4 ms 21084 KB Output is correct
12 Correct 4 ms 21296 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 4 ms 21332 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 5 ms 21324 KB Output is correct
18 Correct 4 ms 21084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21296 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21340 KB Output is correct
9 Correct 4 ms 21340 KB Output is correct
10 Correct 5 ms 21284 KB Output is correct
11 Correct 4 ms 21084 KB Output is correct
12 Correct 4 ms 21296 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 4 ms 21332 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 5 ms 21324 KB Output is correct
18 Correct 4 ms 21084 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 4 ms 21088 KB Output is correct
21 Correct 5 ms 21340 KB Output is correct
22 Correct 6 ms 21424 KB Output is correct
23 Correct 5 ms 21596 KB Output is correct
24 Correct 5 ms 21592 KB Output is correct
25 Correct 5 ms 21592 KB Output is correct
26 Correct 5 ms 21600 KB Output is correct
27 Correct 5 ms 21308 KB Output is correct
28 Correct 7 ms 21600 KB Output is correct
29 Correct 5 ms 21436 KB Output is correct
30 Correct 6 ms 21848 KB Output is correct
31 Correct 5 ms 21596 KB Output is correct
32 Correct 5 ms 21336 KB Output is correct
33 Correct 6 ms 21596 KB Output is correct
34 Correct 5 ms 21492 KB Output is correct
35 Correct 6 ms 21448 KB Output is correct
36 Correct 5 ms 21344 KB Output is correct
37 Correct 5 ms 21340 KB Output is correct
38 Correct 5 ms 21340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21296 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21340 KB Output is correct
9 Correct 4 ms 21340 KB Output is correct
10 Correct 5 ms 21284 KB Output is correct
11 Correct 4 ms 21084 KB Output is correct
12 Correct 4 ms 21296 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 4 ms 21332 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 5 ms 21324 KB Output is correct
18 Correct 4 ms 21084 KB Output is correct
19 Correct 125 ms 49000 KB Output is correct
20 Correct 128 ms 49924 KB Output is correct
21 Correct 128 ms 49008 KB Output is correct
22 Correct 132 ms 48084 KB Output is correct
23 Correct 145 ms 63036 KB Output is correct
24 Correct 100 ms 48584 KB Output is correct
25 Correct 123 ms 53052 KB Output is correct
26 Correct 69 ms 56932 KB Output is correct
27 Correct 187 ms 58064 KB Output is correct
28 Correct 234 ms 90796 KB Output is correct
29 Correct 246 ms 89632 KB Output is correct
30 Correct 160 ms 58672 KB Output is correct
31 Correct 155 ms 58404 KB Output is correct
32 Correct 265 ms 58400 KB Output is correct
33 Correct 181 ms 60472 KB Output is correct
34 Correct 258 ms 92792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 21296 KB Output is correct
2 Correct 4 ms 21084 KB Output is correct
3 Correct 4 ms 21084 KB Output is correct
4 Correct 4 ms 21084 KB Output is correct
5 Correct 4 ms 21080 KB Output is correct
6 Correct 4 ms 21084 KB Output is correct
7 Correct 4 ms 21084 KB Output is correct
8 Correct 4 ms 21340 KB Output is correct
9 Correct 4 ms 21340 KB Output is correct
10 Correct 5 ms 21284 KB Output is correct
11 Correct 4 ms 21084 KB Output is correct
12 Correct 4 ms 21296 KB Output is correct
13 Correct 4 ms 21084 KB Output is correct
14 Correct 4 ms 21084 KB Output is correct
15 Correct 4 ms 21332 KB Output is correct
16 Correct 4 ms 21084 KB Output is correct
17 Correct 5 ms 21324 KB Output is correct
18 Correct 4 ms 21084 KB Output is correct
19 Correct 5 ms 21084 KB Output is correct
20 Correct 4 ms 21088 KB Output is correct
21 Correct 5 ms 21340 KB Output is correct
22 Correct 6 ms 21424 KB Output is correct
23 Correct 5 ms 21596 KB Output is correct
24 Correct 5 ms 21592 KB Output is correct
25 Correct 5 ms 21592 KB Output is correct
26 Correct 5 ms 21600 KB Output is correct
27 Correct 5 ms 21308 KB Output is correct
28 Correct 7 ms 21600 KB Output is correct
29 Correct 5 ms 21436 KB Output is correct
30 Correct 6 ms 21848 KB Output is correct
31 Correct 5 ms 21596 KB Output is correct
32 Correct 5 ms 21336 KB Output is correct
33 Correct 6 ms 21596 KB Output is correct
34 Correct 5 ms 21492 KB Output is correct
35 Correct 6 ms 21448 KB Output is correct
36 Correct 5 ms 21344 KB Output is correct
37 Correct 5 ms 21340 KB Output is correct
38 Correct 5 ms 21340 KB Output is correct
39 Correct 125 ms 49000 KB Output is correct
40 Correct 128 ms 49924 KB Output is correct
41 Correct 128 ms 49008 KB Output is correct
42 Correct 132 ms 48084 KB Output is correct
43 Correct 145 ms 63036 KB Output is correct
44 Correct 100 ms 48584 KB Output is correct
45 Correct 123 ms 53052 KB Output is correct
46 Correct 69 ms 56932 KB Output is correct
47 Correct 187 ms 58064 KB Output is correct
48 Correct 234 ms 90796 KB Output is correct
49 Correct 246 ms 89632 KB Output is correct
50 Correct 160 ms 58672 KB Output is correct
51 Correct 155 ms 58404 KB Output is correct
52 Correct 265 ms 58400 KB Output is correct
53 Correct 181 ms 60472 KB Output is correct
54 Correct 258 ms 92792 KB Output is correct
55 Correct 15 ms 24492 KB Output is correct
56 Correct 13 ms 23412 KB Output is correct
57 Correct 65 ms 43976 KB Output is correct
58 Correct 41 ms 35532 KB Output is correct
59 Correct 72 ms 57216 KB Output is correct
60 Correct 205 ms 89968 KB Output is correct
61 Correct 192 ms 63376 KB Output is correct
62 Correct 159 ms 58580 KB Output is correct
63 Correct 222 ms 58312 KB Output is correct
64 Correct 361 ms 115376 KB Output is correct
65 Correct 364 ms 108612 KB Output is correct
66 Correct 230 ms 84580 KB Output is correct
67 Correct 168 ms 49048 KB Output is correct
68 Correct 321 ms 73024 KB Output is correct
69 Correct 344 ms 76292 KB Output is correct
70 Correct 296 ms 71376 KB Output is correct