Submission #1095415

# Submission time Handle Problem Language Result Execution time Memory
1095415 2024-10-02T05:07:33 Z MtSaka Race (IOI11_race) C++17
100 / 100
272 ms 79208 KB
#include"bits/stdc++.h"
#include "race.h"
#define overload(a,b,c,d,...) d
#define rep1(i,a) for(ll i=0;i<(ll)(a);++i)
#define rep2(i,a,b) for(ll i=(ll)(a);i<(ll)(b);++i)
#define rep(...) overload(__VA_ARGS__,rep2,rep1)(__VA_ARGS__)
#define rrep1(i,a) for(ll i=(ll)(a)-1;i>=0;--i)
#define rrep2(i,a,b) for(ll i=(ll)(b)-1;i>=(ll)(a);--i)
#define rrep(...) overload(__VA_ARGS__,rrep2,rrep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll=long long;
using ull=unsigned long long;
using i128=__int128_t;
using ld=long double;
using vi=vector<int>;
using vl=vector<ll>;
template<typename T,typename U>inline bool chmin(T&a,const U&b){return (a>b?a=b,true:false);}
template<typename T,typename U>inline bool chmax(T&a,const U&b){return (a<b?a=b,true:false);}

int best_path(int n,int k,int h[][2],int l[]){
    vector<vector<pair<int,ll>>>g(n);
    rep(i,n-1){
        g[h[i][0]].eb(h[i][1],l[i]);
        g[h[i][1]].eb(h[i][0],l[i]);
    }
    vector<pair<ll,int>>dist(n,{1e9,1e9});
    {
        queue<int>que;
        que.emplace(0);
        dist[0]=pair<ll,int>{0,0};
        while(!que.empty()){
            int v=que.front();que.pop();
            for(auto [e,c]:g[v])if(dist[e].second==1e9){
                dist[e].first=dist[v].first+c;
                dist[e].second=dist[v].second+1;
                que.push(e);
            }
        }
    }
    vector<set<pair<int,ll>>>st(n);
    int ans=1e9;
    auto dfs=[&](auto&&dfs,ll v,ll p=-1)->void {
        st[v].emplace(dist[v]);
        for(auto [u,c]:g[v])if(u!=p){
            dfs(dfs,u,v);
            if(st[v].size()<st[u].size())swap(st[u],st[v]);
            for(auto [d1,d2]:st[u]){
                //d1+d-2*dist[v].first=k
                   auto it=st[v].lower_bound({2*dist[v].first+k-d1,-1});
                if(it!=st[v].end()&&it->first==2*dist[v].first+k-d1){
                    chmin(ans,it->second+d2-2*dist[v].second);
                }
            }
            for(auto [d1,d2]:st[u])st[v].emplace(d1,d2);
            st[u].clear();
        }
    };
    dfs(dfs,0);
    if(ans==1e9)ans=-1;
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 692 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 79 ms 17096 KB Output is correct
20 Correct 79 ms 17012 KB Output is correct
21 Correct 72 ms 16980 KB Output is correct
22 Correct 72 ms 16720 KB Output is correct
23 Correct 88 ms 17744 KB Output is correct
24 Correct 64 ms 16412 KB Output is correct
25 Correct 109 ms 34376 KB Output is correct
26 Correct 63 ms 39508 KB Output is correct
27 Correct 128 ms 36780 KB Output is correct
28 Correct 191 ms 79208 KB Output is correct
29 Correct 198 ms 77612 KB Output is correct
30 Correct 133 ms 36980 KB Output is correct
31 Correct 138 ms 36692 KB Output is correct
32 Correct 133 ms 36948 KB Output is correct
33 Correct 124 ms 33104 KB Output is correct
34 Correct 209 ms 46552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 344 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 1 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 452 KB Output is correct
22 Correct 1 ms 604 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 1 ms 604 KB Output is correct
25 Correct 1 ms 460 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 1 ms 600 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 1 ms 692 KB Output is correct
34 Correct 1 ms 600 KB Output is correct
35 Correct 1 ms 604 KB Output is correct
36 Correct 1 ms 604 KB Output is correct
37 Correct 1 ms 604 KB Output is correct
38 Correct 1 ms 604 KB Output is correct
39 Correct 79 ms 17096 KB Output is correct
40 Correct 79 ms 17012 KB Output is correct
41 Correct 72 ms 16980 KB Output is correct
42 Correct 72 ms 16720 KB Output is correct
43 Correct 88 ms 17744 KB Output is correct
44 Correct 64 ms 16412 KB Output is correct
45 Correct 109 ms 34376 KB Output is correct
46 Correct 63 ms 39508 KB Output is correct
47 Correct 128 ms 36780 KB Output is correct
48 Correct 191 ms 79208 KB Output is correct
49 Correct 198 ms 77612 KB Output is correct
50 Correct 133 ms 36980 KB Output is correct
51 Correct 138 ms 36692 KB Output is correct
52 Correct 133 ms 36948 KB Output is correct
53 Correct 124 ms 33104 KB Output is correct
54 Correct 209 ms 46552 KB Output is correct
55 Correct 9 ms 2648 KB Output is correct
56 Correct 6 ms 2100 KB Output is correct
57 Correct 50 ms 17016 KB Output is correct
58 Correct 32 ms 16320 KB Output is correct
59 Correct 59 ms 39616 KB Output is correct
60 Correct 206 ms 78160 KB Output is correct
61 Correct 143 ms 40888 KB Output is correct
62 Correct 116 ms 36948 KB Output is correct
63 Correct 132 ms 36944 KB Output is correct
64 Correct 272 ms 45536 KB Output is correct
65 Correct 257 ms 46928 KB Output is correct
66 Correct 210 ms 74064 KB Output is correct
67 Correct 89 ms 33468 KB Output is correct
68 Correct 193 ms 45756 KB Output is correct
69 Correct 223 ms 50772 KB Output is correct
70 Correct 175 ms 43600 KB Output is correct