Submission #1099303

# Submission time Handle Problem Language Result Execution time Memory
1099303 2024-10-11T06:47:58 Z m5588ohammed Race (IOI11_race) C++14
100 / 100
277 ms 95620 KB
#include <bits/stdc++.h>
using namespace std;
#define MAX_N 300000
long long n,k,val=0;
long long ans=1e7;
long long cnst1[MAX_N],cnst2[MAX_N];
vector <array<long long,2>> v[MAX_N];
set <array<long long,2>> nodes[MAX_N];
void dfs(long long i,long long last){
    if(v[i].size()==1&&i!=1){
        nodes[i].insert({0,0});
        return;
    }
    long long x,siz=0,c;
    for(auto [j,w]:v[i]){
        if(j==last) continue;
        dfs(j,i);
        if(nodes[j].size()>siz){
            siz=nodes[j].size();
            x=j;
            c=w;
        }
    }
    swap(nodes[i],nodes[x]);
    nodes[i].insert({0-cnst1[x],0-cnst2[x]});
    long long co=c,le=1;
    auto it=nodes[i].lower_bound({(long long)k-cnst1[x]-co,-10000000ll});
    if(it!=nodes[i].end()&&(*it)[0]==(long long)k-cnst1[x]-co){
        ans=min(ans,le+(*it)[1]+cnst2[x]);
    }
    cnst1[i]=cnst1[x]+c,cnst2[i]=cnst2[x]+1;
    nodes[i].insert({co-cnst1[i],le-cnst2[i]});
    for(auto [j,w]:v[i]){
        if(j==last||j==x) continue;

        co=w,le=1;
        auto it=nodes[i].lower_bound({(long long)k-cnst1[i]-co,-10000000ll});
        if(it!=nodes[i].end()&&(*it)[0]==(long long)k-cnst1[i]-co){
            ans=min(ans,le+(*it)[1]+cnst2[i]);
        }
        nodes[i].insert({co-cnst1[i],le-cnst2[i]});

        for(auto [cost,len]:nodes[j]){
            co=cost+cnst1[j]+w,le=len+cnst2[j]+1;
            it=nodes[i].lower_bound({(long long)k-cnst1[i]-co,-10000000ll});
            if(it!=nodes[i].end()&&(*it)[0]==(long long)k-cnst1[i]-co){
                ans=min(ans,le+(*it)[1]+cnst2[i]);
            }
        }
        for(auto [cost,len]:nodes[j]){
            co=cost+cnst1[j]+w,le=len+cnst2[j]+1;
            nodes[i].insert({co-cnst1[i],le-cnst2[i]});
        }
        nodes[j].clear();
    }
    return;
}
int best_path(int N, int K, int H[][2], int L[])
{
    n=N;
    k=K;
    for(int i=0;i<n-1;i++){
        v[H[i][0]+1].push_back({H[i][1]+1,L[i]});
        v[H[i][1]+1].push_back({H[i][0]+1,L[i]});
        if(L[i]==k) return 1;
    }
    dfs(1,0);
    if(ans!=1e7) return (int)ans;
    else return -1;
}

Compilation message

race.cpp: In function 'void dfs(long long int, long long int)':
race.cpp:15:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   15 |     for(auto [j,w]:v[i]){
      |              ^
race.cpp:18:27: warning: comparison of integer expressions of different signedness: 'std::set<std::array<long long int, 2> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   18 |         if(nodes[j].size()>siz){
      |            ~~~~~~~~~~~~~~~^~~~
race.cpp:33:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   33 |     for(auto [j,w]:v[i]){
      |              ^
race.cpp:43:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   43 |         for(auto [cost,len]:nodes[j]){
      |                  ^
race.cpp:50:18: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   50 |         for(auto [cost,len]:nodes[j]){
      |                  ^
race.cpp:27:56: warning: 'c' may be used uninitialized in this function [-Wmaybe-uninitialized]
   27 |     auto it=nodes[i].lower_bound({(long long)k-cnst1[x]-co,-10000000ll});
      |                                   ~~~~~~~~~~~~~~~~~~~~~^~~
race.cpp:14:15: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   14 |     long long x,siz=0,c;
      |               ^
# Verdict Execution time Memory Grader output
1 Correct 8 ms 21596 KB Output is correct
2 Correct 8 ms 21596 KB Output is correct
3 Correct 8 ms 21596 KB Output is correct
4 Correct 8 ms 21456 KB Output is correct
5 Correct 9 ms 21548 KB Output is correct
6 Correct 8 ms 21592 KB Output is correct
7 Correct 8 ms 21596 KB Output is correct
8 Correct 8 ms 21592 KB Output is correct
9 Correct 8 ms 21596 KB Output is correct
10 Correct 8 ms 21592 KB Output is correct
11 Correct 11 ms 21596 KB Output is correct
12 Correct 8 ms 21596 KB Output is correct
13 Correct 8 ms 21516 KB Output is correct
14 Correct 8 ms 21596 KB Output is correct
15 Correct 8 ms 21444 KB Output is correct
16 Correct 9 ms 21592 KB Output is correct
17 Correct 8 ms 21592 KB Output is correct
18 Correct 8 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 21596 KB Output is correct
2 Correct 8 ms 21596 KB Output is correct
3 Correct 8 ms 21596 KB Output is correct
4 Correct 8 ms 21456 KB Output is correct
5 Correct 9 ms 21548 KB Output is correct
6 Correct 8 ms 21592 KB Output is correct
7 Correct 8 ms 21596 KB Output is correct
8 Correct 8 ms 21592 KB Output is correct
9 Correct 8 ms 21596 KB Output is correct
10 Correct 8 ms 21592 KB Output is correct
11 Correct 11 ms 21596 KB Output is correct
12 Correct 8 ms 21596 KB Output is correct
13 Correct 8 ms 21516 KB Output is correct
14 Correct 8 ms 21596 KB Output is correct
15 Correct 8 ms 21444 KB Output is correct
16 Correct 9 ms 21592 KB Output is correct
17 Correct 8 ms 21592 KB Output is correct
18 Correct 8 ms 21596 KB Output is correct
19 Correct 8 ms 21596 KB Output is correct
20 Correct 8 ms 21568 KB Output is correct
21 Correct 8 ms 21596 KB Output is correct
22 Correct 8 ms 21592 KB Output is correct
23 Correct 9 ms 21528 KB Output is correct
24 Correct 9 ms 21736 KB Output is correct
25 Correct 10 ms 21596 KB Output is correct
26 Correct 9 ms 21596 KB Output is correct
27 Correct 11 ms 21596 KB Output is correct
28 Correct 11 ms 21596 KB Output is correct
29 Correct 9 ms 21580 KB Output is correct
30 Correct 9 ms 21596 KB Output is correct
31 Correct 9 ms 21596 KB Output is correct
32 Correct 9 ms 21596 KB Output is correct
33 Correct 9 ms 21596 KB Output is correct
34 Correct 10 ms 21596 KB Output is correct
35 Correct 11 ms 21596 KB Output is correct
36 Correct 9 ms 21600 KB Output is correct
37 Correct 9 ms 21596 KB Output is correct
38 Correct 9 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 21596 KB Output is correct
2 Correct 8 ms 21596 KB Output is correct
3 Correct 8 ms 21596 KB Output is correct
4 Correct 8 ms 21456 KB Output is correct
5 Correct 9 ms 21548 KB Output is correct
6 Correct 8 ms 21592 KB Output is correct
7 Correct 8 ms 21596 KB Output is correct
8 Correct 8 ms 21592 KB Output is correct
9 Correct 8 ms 21596 KB Output is correct
10 Correct 8 ms 21592 KB Output is correct
11 Correct 11 ms 21596 KB Output is correct
12 Correct 8 ms 21596 KB Output is correct
13 Correct 8 ms 21516 KB Output is correct
14 Correct 8 ms 21596 KB Output is correct
15 Correct 8 ms 21444 KB Output is correct
16 Correct 9 ms 21592 KB Output is correct
17 Correct 8 ms 21592 KB Output is correct
18 Correct 8 ms 21596 KB Output is correct
19 Correct 83 ms 31104 KB Output is correct
20 Correct 80 ms 31312 KB Output is correct
21 Correct 79 ms 31148 KB Output is correct
22 Correct 77 ms 31060 KB Output is correct
23 Correct 23 ms 24144 KB Output is correct
24 Correct 77 ms 30804 KB Output is correct
25 Correct 108 ms 51024 KB Output is correct
26 Correct 75 ms 58396 KB Output is correct
27 Correct 128 ms 47188 KB Output is correct
28 Correct 193 ms 95620 KB Output is correct
29 Correct 192 ms 93404 KB Output is correct
30 Correct 127 ms 47040 KB Output is correct
31 Correct 127 ms 47188 KB Output is correct
32 Correct 157 ms 47188 KB Output is correct
33 Correct 129 ms 40288 KB Output is correct
34 Correct 213 ms 53840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 21596 KB Output is correct
2 Correct 8 ms 21596 KB Output is correct
3 Correct 8 ms 21596 KB Output is correct
4 Correct 8 ms 21456 KB Output is correct
5 Correct 9 ms 21548 KB Output is correct
6 Correct 8 ms 21592 KB Output is correct
7 Correct 8 ms 21596 KB Output is correct
8 Correct 8 ms 21592 KB Output is correct
9 Correct 8 ms 21596 KB Output is correct
10 Correct 8 ms 21592 KB Output is correct
11 Correct 11 ms 21596 KB Output is correct
12 Correct 8 ms 21596 KB Output is correct
13 Correct 8 ms 21516 KB Output is correct
14 Correct 8 ms 21596 KB Output is correct
15 Correct 8 ms 21444 KB Output is correct
16 Correct 9 ms 21592 KB Output is correct
17 Correct 8 ms 21592 KB Output is correct
18 Correct 8 ms 21596 KB Output is correct
19 Correct 8 ms 21596 KB Output is correct
20 Correct 8 ms 21568 KB Output is correct
21 Correct 8 ms 21596 KB Output is correct
22 Correct 8 ms 21592 KB Output is correct
23 Correct 9 ms 21528 KB Output is correct
24 Correct 9 ms 21736 KB Output is correct
25 Correct 10 ms 21596 KB Output is correct
26 Correct 9 ms 21596 KB Output is correct
27 Correct 11 ms 21596 KB Output is correct
28 Correct 11 ms 21596 KB Output is correct
29 Correct 9 ms 21580 KB Output is correct
30 Correct 9 ms 21596 KB Output is correct
31 Correct 9 ms 21596 KB Output is correct
32 Correct 9 ms 21596 KB Output is correct
33 Correct 9 ms 21596 KB Output is correct
34 Correct 10 ms 21596 KB Output is correct
35 Correct 11 ms 21596 KB Output is correct
36 Correct 9 ms 21600 KB Output is correct
37 Correct 9 ms 21596 KB Output is correct
38 Correct 9 ms 21596 KB Output is correct
39 Correct 83 ms 31104 KB Output is correct
40 Correct 80 ms 31312 KB Output is correct
41 Correct 79 ms 31148 KB Output is correct
42 Correct 77 ms 31060 KB Output is correct
43 Correct 23 ms 24144 KB Output is correct
44 Correct 77 ms 30804 KB Output is correct
45 Correct 108 ms 51024 KB Output is correct
46 Correct 75 ms 58396 KB Output is correct
47 Correct 128 ms 47188 KB Output is correct
48 Correct 193 ms 95620 KB Output is correct
49 Correct 192 ms 93404 KB Output is correct
50 Correct 127 ms 47040 KB Output is correct
51 Correct 127 ms 47188 KB Output is correct
52 Correct 157 ms 47188 KB Output is correct
53 Correct 129 ms 40288 KB Output is correct
54 Correct 213 ms 53840 KB Output is correct
55 Correct 16 ms 23128 KB Output is correct
56 Correct 14 ms 22320 KB Output is correct
57 Correct 47 ms 30388 KB Output is correct
58 Correct 43 ms 34756 KB Output is correct
59 Correct 70 ms 58392 KB Output is correct
60 Correct 177 ms 94108 KB Output is correct
61 Correct 157 ms 48976 KB Output is correct
62 Correct 124 ms 47192 KB Output is correct
63 Correct 153 ms 47184 KB Output is correct
64 Correct 277 ms 52600 KB Output is correct
65 Correct 263 ms 54444 KB Output is correct
66 Correct 202 ms 88316 KB Output is correct
67 Correct 115 ms 51892 KB Output is correct
68 Correct 227 ms 53072 KB Output is correct
69 Correct 235 ms 53076 KB Output is correct
70 Correct 220 ms 51708 KB Output is correct