Submission #1093774

# Submission time Handle Problem Language Result Execution time Memory
1093774 2024-09-27T11:43:51 Z asli_bg Race (IOI11_race) C++11
100 / 100
325 ms 109648 KB
#pragma GCC optimize("O3,unroll-loops")
#include "race.h"

#include <bits/stdc++.h>
using namespace std;

#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define pb push_back
 
#define FOR(i,a) for(int i=0;i<(a);i++)
#define FORE(i,a,b) for(int i=(a);i<(b);i++)
#define cont(x) {for(auto el:x) cout<<el<<' ';cout<<endl;}
#define contp(x) {for(auto el:x) cout<<el.fi<<'-'<<el.se<<' ';cout<<endl;}
#define sp <<" "<<
#define mid (l+r)/2
#define endl '\n'
 
#define DEBUG(X) {cout<<#X<<' '<<(X)<<endl;}
 
#define carp(x,y) ((x%MOD)*(y%MOD))%MOD
#define topla(x,y) ((x%MOD)+(y%MOD))%MOD
 
typedef vector<int> vi;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pii> vii;
typedef vector<bool> vb;

const int MAXN=3e5+5;
const ll INF=INT_MAX;
const int MOD=1e9+7;
 
vii adj[MAXN];
ll n,k;
ll res;
pll t[MAXN];
set<pll> s[MAXN];

void merge(ll nd, ll kom){
    auto aranan=k+2*t[nd].se;
    auto cikar=t[nd].fi;

    if(s[nd].size()<s[kom].size()) swap(s[nd],s[kom]);
    //setteki elemanlar--> {dist,edge sayisi}
    //adjdeki elemanlar--> {kom,dist}
    
    //önce cevabı bul
    for(auto el:s[kom]){
        auto deg=aranan-el.fi;
        auto it=s[nd].lower_bound({deg,0});
        if(it==s[nd].end()) continue;
        auto bir=(*it).fi; //distance
        auto iki=(*it).se; //no of edges
        if(bir==deg){
            res=min(res,iki+el.se-2*cikar);
        }
    }

    //sonra insertle
    for(auto el:s[kom]) s[nd].insert(el);
}

void dfs(ll nd,ll ata,ll h,ll edg){
    t[nd]={edg,h};

    for(auto el:adj[nd]){
        auto kom=el.fi;
        auto cost=el.se;
        if(kom!=ata){
            dfs(kom,nd,h+cost,edg+1);
            merge(nd,kom);
        }
    }

    auto aranan=k+t[nd].se;
    auto cikar=t[nd].fi;

    auto it=s[nd].lower_bound({aranan,0});
    if(it!=s[nd].end()){
        if((*it).fi==aranan){
            res=min(res,(*it).se-cikar);
        }
    }
    s[nd].insert({t[nd].se,t[nd].fi});
}


int best_path(int N, int K, int H[][2], int L[]){
    //#define int long long
    res=INF;
    k=K;
    n=N;
    FOR(i,n-1){
        adj[H[i][0]+1].pb({H[i][1]+1,L[i]});
        adj[H[i][1]+1].pb({H[i][0]+1,L[i]});
    }
    
    dfs(1,0,0,0);

    //#undef int

    if(res==INF) res=-1;
    return res;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21592 KB Output is correct
2 Correct 10 ms 21600 KB Output is correct
3 Correct 11 ms 21584 KB Output is correct
4 Correct 10 ms 21596 KB Output is correct
5 Correct 10 ms 21596 KB Output is correct
6 Correct 9 ms 21596 KB Output is correct
7 Correct 11 ms 21600 KB Output is correct
8 Correct 12 ms 21432 KB Output is correct
9 Correct 11 ms 21592 KB Output is correct
10 Correct 11 ms 21600 KB Output is correct
11 Correct 10 ms 21588 KB Output is correct
12 Correct 11 ms 21372 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 11 ms 21596 KB Output is correct
15 Correct 10 ms 21596 KB Output is correct
16 Correct 10 ms 21596 KB Output is correct
17 Correct 10 ms 21592 KB Output is correct
18 Correct 14 ms 21552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21592 KB Output is correct
2 Correct 10 ms 21600 KB Output is correct
3 Correct 11 ms 21584 KB Output is correct
4 Correct 10 ms 21596 KB Output is correct
5 Correct 10 ms 21596 KB Output is correct
6 Correct 9 ms 21596 KB Output is correct
7 Correct 11 ms 21600 KB Output is correct
8 Correct 12 ms 21432 KB Output is correct
9 Correct 11 ms 21592 KB Output is correct
10 Correct 11 ms 21600 KB Output is correct
11 Correct 10 ms 21588 KB Output is correct
12 Correct 11 ms 21372 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 11 ms 21596 KB Output is correct
15 Correct 10 ms 21596 KB Output is correct
16 Correct 10 ms 21596 KB Output is correct
17 Correct 10 ms 21592 KB Output is correct
18 Correct 14 ms 21552 KB Output is correct
19 Correct 10 ms 21596 KB Output is correct
20 Correct 10 ms 21564 KB Output is correct
21 Correct 11 ms 21596 KB Output is correct
22 Correct 10 ms 21856 KB Output is correct
23 Correct 10 ms 21692 KB Output is correct
24 Correct 17 ms 21852 KB Output is correct
25 Correct 10 ms 21792 KB Output is correct
26 Correct 11 ms 21848 KB Output is correct
27 Correct 10 ms 21596 KB Output is correct
28 Correct 12 ms 21684 KB Output is correct
29 Correct 11 ms 21852 KB Output is correct
30 Correct 11 ms 21708 KB Output is correct
31 Correct 10 ms 21768 KB Output is correct
32 Correct 11 ms 21852 KB Output is correct
33 Correct 11 ms 21856 KB Output is correct
34 Correct 14 ms 21596 KB Output is correct
35 Correct 12 ms 21596 KB Output is correct
36 Correct 10 ms 21596 KB Output is correct
37 Correct 10 ms 21596 KB Output is correct
38 Correct 11 ms 21596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21592 KB Output is correct
2 Correct 10 ms 21600 KB Output is correct
3 Correct 11 ms 21584 KB Output is correct
4 Correct 10 ms 21596 KB Output is correct
5 Correct 10 ms 21596 KB Output is correct
6 Correct 9 ms 21596 KB Output is correct
7 Correct 11 ms 21600 KB Output is correct
8 Correct 12 ms 21432 KB Output is correct
9 Correct 11 ms 21592 KB Output is correct
10 Correct 11 ms 21600 KB Output is correct
11 Correct 10 ms 21588 KB Output is correct
12 Correct 11 ms 21372 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 11 ms 21596 KB Output is correct
15 Correct 10 ms 21596 KB Output is correct
16 Correct 10 ms 21596 KB Output is correct
17 Correct 10 ms 21592 KB Output is correct
18 Correct 14 ms 21552 KB Output is correct
19 Correct 97 ms 45444 KB Output is correct
20 Correct 95 ms 45244 KB Output is correct
21 Correct 87 ms 44884 KB Output is correct
22 Correct 91 ms 44116 KB Output is correct
23 Correct 126 ms 58704 KB Output is correct
24 Correct 100 ms 47700 KB Output is correct
25 Correct 87 ms 43512 KB Output is correct
26 Correct 60 ms 45904 KB Output is correct
27 Correct 142 ms 53264 KB Output is correct
28 Correct 166 ms 70708 KB Output is correct
29 Correct 169 ms 69968 KB Output is correct
30 Correct 139 ms 53328 KB Output is correct
31 Correct 141 ms 53332 KB Output is correct
32 Correct 180 ms 53464 KB Output is correct
33 Correct 136 ms 48724 KB Output is correct
34 Correct 225 ms 81676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 21592 KB Output is correct
2 Correct 10 ms 21600 KB Output is correct
3 Correct 11 ms 21584 KB Output is correct
4 Correct 10 ms 21596 KB Output is correct
5 Correct 10 ms 21596 KB Output is correct
6 Correct 9 ms 21596 KB Output is correct
7 Correct 11 ms 21600 KB Output is correct
8 Correct 12 ms 21432 KB Output is correct
9 Correct 11 ms 21592 KB Output is correct
10 Correct 11 ms 21600 KB Output is correct
11 Correct 10 ms 21588 KB Output is correct
12 Correct 11 ms 21372 KB Output is correct
13 Correct 11 ms 21596 KB Output is correct
14 Correct 11 ms 21596 KB Output is correct
15 Correct 10 ms 21596 KB Output is correct
16 Correct 10 ms 21596 KB Output is correct
17 Correct 10 ms 21592 KB Output is correct
18 Correct 14 ms 21552 KB Output is correct
19 Correct 10 ms 21596 KB Output is correct
20 Correct 10 ms 21564 KB Output is correct
21 Correct 11 ms 21596 KB Output is correct
22 Correct 10 ms 21856 KB Output is correct
23 Correct 10 ms 21692 KB Output is correct
24 Correct 17 ms 21852 KB Output is correct
25 Correct 10 ms 21792 KB Output is correct
26 Correct 11 ms 21848 KB Output is correct
27 Correct 10 ms 21596 KB Output is correct
28 Correct 12 ms 21684 KB Output is correct
29 Correct 11 ms 21852 KB Output is correct
30 Correct 11 ms 21708 KB Output is correct
31 Correct 10 ms 21768 KB Output is correct
32 Correct 11 ms 21852 KB Output is correct
33 Correct 11 ms 21856 KB Output is correct
34 Correct 14 ms 21596 KB Output is correct
35 Correct 12 ms 21596 KB Output is correct
36 Correct 10 ms 21596 KB Output is correct
37 Correct 10 ms 21596 KB Output is correct
38 Correct 11 ms 21596 KB Output is correct
39 Correct 97 ms 45444 KB Output is correct
40 Correct 95 ms 45244 KB Output is correct
41 Correct 87 ms 44884 KB Output is correct
42 Correct 91 ms 44116 KB Output is correct
43 Correct 126 ms 58704 KB Output is correct
44 Correct 100 ms 47700 KB Output is correct
45 Correct 87 ms 43512 KB Output is correct
46 Correct 60 ms 45904 KB Output is correct
47 Correct 142 ms 53264 KB Output is correct
48 Correct 166 ms 70708 KB Output is correct
49 Correct 169 ms 69968 KB Output is correct
50 Correct 139 ms 53328 KB Output is correct
51 Correct 141 ms 53332 KB Output is correct
52 Correct 180 ms 53464 KB Output is correct
53 Correct 136 ms 48724 KB Output is correct
54 Correct 225 ms 81676 KB Output is correct
55 Correct 21 ms 24664 KB Output is correct
56 Correct 15 ms 23388 KB Output is correct
57 Correct 56 ms 40708 KB Output is correct
58 Correct 39 ms 35364 KB Output is correct
59 Correct 60 ms 45904 KB Output is correct
60 Correct 149 ms 69968 KB Output is correct
61 Correct 182 ms 58992 KB Output is correct
62 Correct 142 ms 53452 KB Output is correct
63 Correct 161 ms 53540 KB Output is correct
64 Correct 325 ms 109648 KB Output is correct
65 Correct 276 ms 103008 KB Output is correct
66 Correct 189 ms 68688 KB Output is correct
67 Correct 128 ms 50848 KB Output is correct
68 Correct 259 ms 70916 KB Output is correct
69 Correct 310 ms 76612 KB Output is correct
70 Correct 241 ms 68944 KB Output is correct