Submission #525125

# Submission time Handle Problem Language Result Execution time Memory
525125 2022-02-10T19:31:01 Z leaked Highway Tolls (IOI18_highway) C++14
100 / 100
241 ms 13488 KB
#include "highway.h"
#include <bits/stdc++.h>


#define f first
#define s second
#define m_p make_pair
#define vec vector
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define sz(x) (int)(x).size()
#define pw(x) (1LL<<(x))

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;

const int N=1e5+1;
vec<pii> g[N];
int p[N];
void find_pair(int n,vec<int> _v,vec<int> _u,int a,int b){
    int m=sz(_u);
    int l=0,r=m-1;
    vec<int>kek(m,0);
    ll dst=ask(kek);
    ll lst=N;
//    cout<<dst<<endl;
    auto check=[&](vec<int> ids){
        vec<int> w(m,0);
        for(auto &z : ids) w[z]=1;
        return ask(w);
    };
    auto check1=[&](vec<int> ids){
        vec<int> w(m,1);
        for(auto &z : ids) w[z]=0;
        return ask(w);
    };

    while(l!=r){
        int tm=(l+r)>>1;
        vec<int>ids;
        for(int j=0;j<=tm;j++)
            ids.pb(j);
        lst=check(ids);
//        cout<<dst<<' '<<check(ids)<<endl;
        if(lst>dst)
            r=tm;
        else
            l=tm+1;
    }
    for(int i=0;i<m;i++){
        g[_v[i]].pb({_u[i],i});
        g[_u[i]].pb({_v[i],i});
    }
    assert(lst!=0);
//    cout<<"ALO "<<a<<' '<<b<<' '<<lst<<' '<<lst+b+a<<' '<<(lst-a)/b*a +a<<endl;
    int v=_v[l],u=_u[l];
    queue<int>q;
    vec<int>d1(n,2e9),d2(n,2e9);
    vec<int>p1(n),p2(n);
    p1[v]=l;d1[v]=0;
    q.push(v);
    while(!q.empty()){
        int ct=q.front();q.pop();
        for(auto &z : g[ct]){
            if(d1[z.f]>d1[ct]+1){
                d1[z.f]=d1[ct]+1;
                p1[z.f]=z.s;
                q.push(z.f);
            }
        }
    }
    p2[u]=l;d2[u]=0;
    q.push(u);
    while(!q.empty()){
        int ct=q.front();q.pop();
        for(auto &z : g[ct]){
            if(d2[z.f]>d2[ct]+1){
                d2[z.f]=d2[ct]+1;
                p2[z.f]=z.s;
//                cout<<"P@ "<<z.f<<' '<<z.s<<endl;
                q.push(z.f);
            }
        }
    }

    ///find s
    vec<int>p;
    vec<int> toadd,vc;
//    for(int i=0;i<m;i++) vc.pb(i);
    for(int i=0;i<n;i++){
        if(d1[i]<d2[i]) p.pb(i);
        else if(d2[i]<d1[i]) toadd.pb(p2[i]);
//        if(d1[i]<d2[i])vc.pb(p1[i]);
//        if(d2[i]<d1[i])vc.pb(p2[i]);
    }
    l=0,r=sz(p)-1;
    ll need=dst;
    sort(all(p),[&](int i,int j){return d1[i]<d1[j];});

    while(l!=r){
        int tm=(l+r)>>1;
        vec<int>ids;
        for(int j=0;j<=tm;j++) ids.pb(p1[p[j]]);
        for(auto &j : toadd) ids.pb(j);
//        cout<<tm<<' '<<need<<' '<<check1(ids)<<endl;
        if(check1(ids)!=need) l=tm+1;
        else r=tm;
    }
    toadd.clear();
//    --l;
    int s=p[l];
    p.clear();
    for(int i=0;i<n;i++){
//        cout<<d1[i]<<' '<<d2[i]<<endl;
        if(d2[i]<d1[i] && i!=v) p.pb(i);
        else if(d1[i]<d2[i] && i!=v) toadd.pb(p1[i]);
    }
//    cout<<p1[s]
    sort(all(p),[&](int i,int j){return d2[i]<d2[j];});
//    for(auto &z : p)
//        cout<<z<<' '<<d2[z]<<endl;
//    cout<<"CHS "<<check(toadd)<<' '<<need<<endl;
    l=0,r=sz(p)-1;
    while(l!=r){
        int tm=(l+r)>>1;
        vec<int>ids;
        for(int j=0;j<=tm;j++) ids.pb(p2[p[j]]);
        for(auto &j : toadd) ids.pb(j);
//        cout<<"AUE "<<tm<<' '<<check(ids)<<' '<<need<<' '<<tm<<endl;
        if(check1(ids)!=need) l=tm+1;
        else r=tm;
    }
    int t=p[l];
//    assert(check({p2[16565]}));
//    cout<<"V "<<v<<' '<<u<<endl;
//    cout<<"AS "<<s<<' '<<t<<' '<<d2[16565]<<' '<<d1[16565]<<endl;
    answer(s,t);
}
/*



*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2632 KB Output is correct
2 Correct 2 ms 2632 KB Output is correct
3 Correct 2 ms 2608 KB Output is correct
4 Correct 2 ms 2632 KB Output is correct
5 Correct 2 ms 2632 KB Output is correct
6 Correct 2 ms 2632 KB Output is correct
7 Correct 2 ms 2632 KB Output is correct
8 Correct 2 ms 2632 KB Output is correct
9 Correct 1 ms 2632 KB Output is correct
10 Correct 1 ms 2632 KB Output is correct
11 Correct 2 ms 2632 KB Output is correct
12 Correct 2 ms 2632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 2632 KB Output is correct
2 Correct 15 ms 3532 KB Output is correct
3 Correct 119 ms 11136 KB Output is correct
4 Correct 121 ms 11368 KB Output is correct
5 Correct 116 ms 11488 KB Output is correct
6 Correct 124 ms 11236 KB Output is correct
7 Correct 163 ms 11148 KB Output is correct
8 Correct 109 ms 10804 KB Output is correct
9 Correct 148 ms 11120 KB Output is correct
10 Correct 133 ms 11364 KB Output is correct
11 Correct 139 ms 10016 KB Output is correct
12 Correct 185 ms 10520 KB Output is correct
13 Correct 155 ms 10280 KB Output is correct
14 Correct 126 ms 10492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3636 KB Output is correct
2 Correct 26 ms 4384 KB Output is correct
3 Correct 38 ms 5212 KB Output is correct
4 Correct 133 ms 10112 KB Output is correct
5 Correct 142 ms 10104 KB Output is correct
6 Correct 103 ms 10428 KB Output is correct
7 Correct 126 ms 10656 KB Output is correct
8 Correct 144 ms 10584 KB Output is correct
9 Correct 103 ms 10596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 2632 KB Output is correct
2 Correct 19 ms 3552 KB Output is correct
3 Correct 102 ms 9128 KB Output is correct
4 Correct 124 ms 10792 KB Output is correct
5 Correct 150 ms 11104 KB Output is correct
6 Correct 108 ms 10804 KB Output is correct
7 Correct 143 ms 11208 KB Output is correct
8 Correct 137 ms 10880 KB Output is correct
9 Correct 128 ms 11148 KB Output is correct
10 Correct 162 ms 11132 KB Output is correct
11 Correct 140 ms 10532 KB Output is correct
12 Correct 173 ms 10464 KB Output is correct
13 Correct 147 ms 10368 KB Output is correct
14 Correct 180 ms 10396 KB Output is correct
15 Correct 122 ms 10804 KB Output is correct
16 Correct 139 ms 10780 KB Output is correct
17 Correct 134 ms 10556 KB Output is correct
18 Correct 172 ms 10564 KB Output is correct
19 Correct 112 ms 11260 KB Output is correct
20 Correct 137 ms 10204 KB Output is correct
21 Correct 145 ms 11668 KB Output is correct
22 Correct 149 ms 10692 KB Output is correct
23 Correct 118 ms 11160 KB Output is correct
24 Correct 139 ms 10996 KB Output is correct
25 Correct 175 ms 10664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 3528 KB Output is correct
2 Correct 17 ms 3640 KB Output is correct
3 Correct 182 ms 11496 KB Output is correct
4 Correct 189 ms 11688 KB Output is correct
5 Correct 186 ms 12784 KB Output is correct
6 Correct 221 ms 12800 KB Output is correct
7 Correct 228 ms 12520 KB Output is correct
8 Correct 238 ms 12660 KB Output is correct
9 Correct 173 ms 9756 KB Output is correct
10 Correct 168 ms 10148 KB Output is correct
11 Correct 196 ms 11240 KB Output is correct
12 Correct 214 ms 11840 KB Output is correct
13 Correct 217 ms 12248 KB Output is correct
14 Correct 165 ms 12788 KB Output is correct
15 Correct 174 ms 13356 KB Output is correct
16 Correct 154 ms 10648 KB Output is correct
17 Correct 125 ms 11928 KB Output is correct
18 Correct 127 ms 11560 KB Output is correct
19 Correct 116 ms 11864 KB Output is correct
20 Correct 113 ms 11640 KB Output is correct
21 Correct 180 ms 12900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 3528 KB Output is correct
2 Correct 23 ms 3712 KB Output is correct
3 Correct 191 ms 11272 KB Output is correct
4 Correct 193 ms 11260 KB Output is correct
5 Correct 158 ms 11680 KB Output is correct
6 Correct 235 ms 12448 KB Output is correct
7 Correct 116 ms 11240 KB Output is correct
8 Correct 183 ms 11356 KB Output is correct
9 Correct 199 ms 11636 KB Output is correct
10 Correct 175 ms 12836 KB Output is correct
11 Correct 228 ms 12368 KB Output is correct
12 Correct 188 ms 12540 KB Output is correct
13 Correct 140 ms 10780 KB Output is correct
14 Correct 141 ms 10368 KB Output is correct
15 Correct 185 ms 10792 KB Output is correct
16 Correct 138 ms 10404 KB Output is correct
17 Correct 198 ms 10780 KB Output is correct
18 Correct 144 ms 10200 KB Output is correct
19 Correct 197 ms 11820 KB Output is correct
20 Correct 223 ms 12524 KB Output is correct
21 Correct 179 ms 12600 KB Output is correct
22 Correct 176 ms 12524 KB Output is correct
23 Correct 228 ms 12404 KB Output is correct
24 Correct 241 ms 12652 KB Output is correct
25 Correct 172 ms 12868 KB Output is correct
26 Correct 171 ms 12660 KB Output is correct
27 Correct 161 ms 11736 KB Output is correct
28 Correct 162 ms 11768 KB Output is correct
29 Correct 139 ms 11372 KB Output is correct
30 Correct 150 ms 11492 KB Output is correct
31 Correct 174 ms 11860 KB Output is correct
32 Correct 157 ms 11428 KB Output is correct
33 Correct 161 ms 11864 KB Output is correct
34 Correct 120 ms 11852 KB Output is correct
35 Correct 128 ms 11972 KB Output is correct
36 Correct 160 ms 11236 KB Output is correct
37 Correct 121 ms 11760 KB Output is correct
38 Correct 119 ms 11244 KB Output is correct
39 Correct 182 ms 12904 KB Output is correct
40 Correct 236 ms 13488 KB Output is correct
41 Correct 194 ms 13204 KB Output is correct
42 Correct 184 ms 12768 KB Output is correct