Submission #933971

# Submission time Handle Problem Language Result Execution time Memory
933971 2024-02-26T15:57:53 Z kim Highway Tolls (IOI18_highway) C++17
100 / 100
202 ms 12664 KB
#include "highway.h"
#include<bits/stdc++.h>
using namespace std;
#define eb emplace_back
using ll=long long;
using pii=pair<int,int>;
#define f first
#define s second
 
int n,m;
pii edge[130005];
vector<pii> graph[90005];
vector<int> tmp,ans;
ll mn_ask,dist;
bitset<90005> vis;
int tour[90005],parent[90005];
 
int solve1(int U){
    int id=0;
    queue<int> q;
    q.emplace(U);
    vis=0;
    vis[U]=1;
    tour[U]=0;
    while(q.size()){
        int u=q.front(); q.pop();
        for(auto &[v,i]:graph[u]){
            if(vis[v]) continue;
            vis[v]=1;
            q.emplace(v);
            tour[v]=++id;
        }
    }
    int l=dist,r=id;
    while(l<r){
        int mid=l+r>>1;
        for(int i=0;i<m;++i){
            auto &[u,v]=edge[i];
            if(tour[u]<=mid&&tour[v]<=mid) tmp[i]=0;
            else tmp[i]=1;
        }
        if(ask(tmp)==mn_ask) r=mid;
        else l=mid+1;
    }
    for(int i=0;i<n;++i){
        if(tour[i]==l){
            ans.eb(i);
            return i;
        }
    }
}
int solve2(int U){
    int id=0;
    queue<int> q;
    q.emplace(U);
    vis=0;
    vis[U]=1;
    tour[U]=0;
    parent[U]=U;
    while(q.size()){
        int u=q.front(); q.pop();
        for(auto &[v,i]:graph[u]){
            if(vis[v]) continue;
            vis[v]=1;
            q.emplace(v);
            tour[v]=++id;
            parent[v]=u;
        }
    }
    int l=dist,r=id;
    while(l<r){
        int mid=l+r>>1;
        for(int i=0;i<m;++i){
            auto &[u,v]=edge[i];
            if(tour[u]<=mid&&tour[v]<=mid) tmp[i]=0;
            else tmp[i]=1;
        }
        if(ask(tmp)==mn_ask) r=mid;
        else l=mid+1;
    }
    int x;
    for(int i=0;i<n;++i){
        graph[i].clear();
        if(tour[i]==l) ans.eb(i),x=i;
    }
    while(parent[x]!=U){
        vis[x]=0;
        x=parent[x];
    }
    vis[x]=0;
    int i0;
    for(int i=0;i<m;++i){
        auto &[u,v]=edge[i];
        if(tour[u]<=l&&tour[v]<=l && vis[u]==vis[v]) graph[u].eb(v,i),graph[v].eb(u,i);
        if(u==x&&v==U||u==U&&v==x) i0=i;
    }
    graph[x].eb(U,i0);
    return ans.back();
}
void solve3(int U){
    queue<pii> q;
    q.emplace(U,0);
    vis=0;
    vis[U]=1;
    vector<int> tmp2(tmp.size(),1);
    vector<pii> vec;
    while(q.size()){
        auto [u,d]=q.front(); q.pop();
        for(auto &[v,id]:graph[u]){
            if(vis[v]) continue;
            if(d+1<dist) q.emplace(v,d+1), tmp2[id]=0;
            else if(d+1==dist) vec.eb(v,id);
            vis[v]=1;
        }
    }
    int l=0,r=vec.size();
    while(l<r){
        int mid=l+r>>1;
        tmp=tmp2;
        for(int i=0;i<=mid;++i) tmp[vec[i].s]=0;
        if(ask(tmp)==mn_ask) r=mid;
        else l=mid+1;
    }
    ans.eb(vec[l].f);
}
 
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n=N,m=U.size();
    for(int i=0;i<m;++i){
        edge[i]={U[i],V[i]};
        graph[U[i]].eb(V[i],i);
        graph[V[i]].eb(U[i],i);
    }
    tmp.assign(m,0);
    mn_ask=ask(tmp), dist=mn_ask/A;
    solve3(solve2(solve1(0)));
    answer(ans[1],ans[2]);
}
/*
15 15  99 100  9 10
0 1
1 3
3 5
5 7
7 9
9 11
11 13
13 14
14 12
12 10
10 8
8 6
6 4
4 2
2 0
*/

Compilation message

highway.cpp: In function 'int solve1(int)':
highway.cpp:36:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   36 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp: In function 'int solve2(int)':
highway.cpp:72:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   72 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp:95:16: warning: suggest parentheses around '&&' within '||' [-Wparentheses]
   95 |         if(u==x&&v==U||u==U&&v==x) i0=i;
      |            ~~~~^~~~~~
highway.cpp: In function 'void solve3(int)':
highway.cpp:118:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  118 |         int mid=l+r>>1;
      |                 ~^~
highway.cpp: In function 'int solve1(int)':
highway.cpp:20:16: warning: control reaches end of non-void function [-Wreturn-type]
   20 |     queue<int> q;
      |                ^
highway.cpp: In function 'int solve2(int)':
highway.cpp:86:19: warning: 'x' may be used uninitialized in this function [-Wmaybe-uninitialized]
   86 |     while(parent[x]!=U){
      |           ~~~~~~~~^
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3104 KB Output is correct
2 Correct 1 ms 3112 KB Output is correct
3 Correct 1 ms 3112 KB Output is correct
4 Correct 1 ms 3108 KB Output is correct
5 Correct 1 ms 3360 KB Output is correct
6 Correct 1 ms 3104 KB Output is correct
7 Correct 1 ms 3360 KB Output is correct
8 Correct 2 ms 3100 KB Output is correct
9 Correct 1 ms 3268 KB Output is correct
10 Correct 1 ms 3108 KB Output is correct
11 Correct 1 ms 3104 KB Output is correct
12 Correct 1 ms 3108 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 3428 KB Output is correct
2 Correct 12 ms 3844 KB Output is correct
3 Correct 116 ms 10208 KB Output is correct
4 Correct 101 ms 10208 KB Output is correct
5 Correct 106 ms 9880 KB Output is correct
6 Correct 133 ms 9732 KB Output is correct
7 Correct 104 ms 9740 KB Output is correct
8 Correct 97 ms 9892 KB Output is correct
9 Correct 100 ms 10392 KB Output is correct
10 Correct 118 ms 9504 KB Output is correct
11 Correct 97 ms 9608 KB Output is correct
12 Correct 130 ms 9140 KB Output is correct
13 Correct 100 ms 9612 KB Output is correct
14 Correct 104 ms 9616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3976 KB Output is correct
2 Correct 20 ms 4364 KB Output is correct
3 Correct 41 ms 5060 KB Output is correct
4 Correct 78 ms 8908 KB Output is correct
5 Correct 75 ms 8908 KB Output is correct
6 Correct 78 ms 9160 KB Output is correct
7 Correct 78 ms 8912 KB Output is correct
8 Correct 89 ms 8904 KB Output is correct
9 Correct 69 ms 9140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 3164 KB Output is correct
2 Correct 16 ms 4084 KB Output is correct
3 Correct 78 ms 8140 KB Output is correct
4 Correct 90 ms 9492 KB Output is correct
5 Correct 116 ms 9808 KB Output is correct
6 Correct 94 ms 9504 KB Output is correct
7 Correct 81 ms 9740 KB Output is correct
8 Correct 101 ms 9832 KB Output is correct
9 Correct 107 ms 9620 KB Output is correct
10 Correct 115 ms 9744 KB Output is correct
11 Correct 140 ms 10104 KB Output is correct
12 Correct 98 ms 8908 KB Output is correct
13 Correct 115 ms 9616 KB Output is correct
14 Correct 121 ms 9620 KB Output is correct
15 Correct 88 ms 9968 KB Output is correct
16 Correct 85 ms 9976 KB Output is correct
17 Correct 130 ms 9432 KB Output is correct
18 Correct 114 ms 9500 KB Output is correct
19 Correct 112 ms 9736 KB Output is correct
20 Correct 98 ms 9388 KB Output is correct
21 Correct 85 ms 10128 KB Output is correct
22 Correct 83 ms 9644 KB Output is correct
23 Correct 90 ms 10284 KB Output is correct
24 Correct 77 ms 9960 KB Output is correct
25 Correct 123 ms 9264 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3856 KB Output is correct
2 Correct 13 ms 3928 KB Output is correct
3 Correct 157 ms 10688 KB Output is correct
4 Correct 129 ms 11104 KB Output is correct
5 Correct 176 ms 11976 KB Output is correct
6 Correct 151 ms 12208 KB Output is correct
7 Correct 160 ms 12500 KB Output is correct
8 Correct 159 ms 11764 KB Output is correct
9 Correct 125 ms 10500 KB Output is correct
10 Correct 148 ms 11436 KB Output is correct
11 Correct 130 ms 11324 KB Output is correct
12 Correct 158 ms 12228 KB Output is correct
13 Correct 138 ms 12012 KB Output is correct
14 Correct 165 ms 12200 KB Output is correct
15 Correct 178 ms 12408 KB Output is correct
16 Correct 122 ms 11416 KB Output is correct
17 Correct 130 ms 9892 KB Output is correct
18 Correct 100 ms 10324 KB Output is correct
19 Correct 121 ms 10228 KB Output is correct
20 Correct 97 ms 10172 KB Output is correct
21 Correct 136 ms 11736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 4084 KB Output is correct
2 Correct 12 ms 4132 KB Output is correct
3 Correct 129 ms 10428 KB Output is correct
4 Correct 127 ms 10960 KB Output is correct
5 Correct 156 ms 11032 KB Output is correct
6 Correct 171 ms 12268 KB Output is correct
7 Correct 118 ms 10540 KB Output is correct
8 Correct 115 ms 10492 KB Output is correct
9 Correct 119 ms 10856 KB Output is correct
10 Correct 137 ms 12052 KB Output is correct
11 Correct 147 ms 12208 KB Output is correct
12 Correct 170 ms 12092 KB Output is correct
13 Correct 136 ms 11800 KB Output is correct
14 Correct 136 ms 10976 KB Output is correct
15 Correct 162 ms 11128 KB Output is correct
16 Correct 121 ms 11428 KB Output is correct
17 Correct 136 ms 11124 KB Output is correct
18 Correct 144 ms 11528 KB Output is correct
19 Correct 155 ms 12232 KB Output is correct
20 Correct 202 ms 11924 KB Output is correct
21 Correct 146 ms 12020 KB Output is correct
22 Correct 181 ms 12468 KB Output is correct
23 Correct 145 ms 12636 KB Output is correct
24 Correct 174 ms 12664 KB Output is correct
25 Correct 172 ms 12004 KB Output is correct
26 Correct 144 ms 12372 KB Output is correct
27 Correct 104 ms 10216 KB Output is correct
28 Correct 111 ms 10252 KB Output is correct
29 Correct 99 ms 10376 KB Output is correct
30 Correct 101 ms 10372 KB Output is correct
31 Correct 90 ms 10732 KB Output is correct
32 Correct 107 ms 10532 KB Output is correct
33 Correct 95 ms 10788 KB Output is correct
34 Correct 120 ms 10300 KB Output is correct
35 Correct 101 ms 10488 KB Output is correct
36 Correct 128 ms 10300 KB Output is correct
37 Correct 107 ms 10144 KB Output is correct
38 Correct 105 ms 10604 KB Output is correct
39 Correct 146 ms 11976 KB Output is correct
40 Correct 142 ms 12408 KB Output is correct
41 Correct 140 ms 11728 KB Output is correct
42 Correct 146 ms 11952 KB Output is correct