Submission #118620

# Submission time Handle Problem Language Result Execution time Memory
118620 2019-06-19T09:57:09 Z someone_aa Highway Tolls (IOI18_highway) C++17
51 / 100
265 ms 12576 KB
#include "highway.h"
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;
const int maxn = 100100;
int n, m;
vector<int>w;
vector<pair<int,int> > g[maxn];
 
int dist[maxn][2], parent[maxn][2];
bool visited[maxn];
 
ll dista;
 
void bfs(int st, int d) {
    memset(visited,false,sizeof(visited));
    queue<int>q;
    q.push(st);
 
    parent[st][d] = -1;
    visited[st] = true;
 
    while(!q.empty()) {
        int curr = q.front();
        q.pop();
 
        for(auto i:g[curr]) {
            if(!visited[i.first]) {
                visited[i.first] = true;
                dist[i.first][d] = dist[curr][d] + 1;
                parent[i.first][d] = i.second;
                q.push(i.first);
            }
        }
    }
}
 
int solve(vector<int> x, int d) {
    vector<int>w;
    for(int i=0;i<m;i++) w.pb(0);
    vector<pair<int,int> > dists;
    for(int i:x) {
        dists.pb(mp(dist[i][d], i));
    }
    sort(dists.begin(), dists.end());
 
    //cout<<d<<": ";
    //for(int i:x) cout<<i<<" ";
    //cout<<"\n";
    for(int i=0;i<m;i++) w[i] = 1;
    for(int i:x) if(parent[i][d] != -1) w[parent[i][d]] = 0;
 
    /*cout<<d<<":\n";
    for(auto i:dists) {
        cout<<i.first<<" "<<i.second<<"\n";
    }*/
 
    ll dista = ask(w);
    int li=0, ri=dists.size()-1;
    while(li<ri) {
        int mid = (li+ri)/2;
 
        for(int i=mid+1;i<=ri;i++) {
            if(parent[dists[i].second][d] != -1)
                w[parent[dists[i].second][d]] = 1;
        }
        ll distb = ask(w);
 
        for(int i=mid+1;i<=ri;i++) {
            if(parent[dists[i].second][d] != -1)
                w[parent[dists[i].second][d]] = 0;
        }
 
        if(dista == distb) {
            ri = mid;
        }
        else {
            li = mid + 1;
        }
    }
    return dists[li].second;
}
 
void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n = N; m = U.size();
    int li=0, ri=m-1;
 
    for(int i=0;i<m;i++) {
        g[U[i]].pb(mp(V[i], i));
        g[V[i]].pb(mp(U[i], i));
    }
 
    for(int i=0;i<m;i++) w.pb(0);
    dista = ask(w);
 
    while(li<ri) {
        int mid = (li+ri)/2;
        for(int i=li;i<=mid;i++) {
            w[i] = 1;
        }
        ll distb = ask(w);
        for(int i=li;i<=mid;i++) {
            w[i] = 0;
        }
        if(dista == distb) {
            li = mid + 1;
        }
        else {
            ri = mid;
        }
    }
    int x = li;
    int u = U[x], v = V[x];
    bfs(u, 0);
    bfs(v, 1);
 
    vector<int>su, sv;
    for(int i=0;i<n;i++) {
        if(dist[i][0] <= dist[i][1]) {
            su.pb(i);
        }
        else {
            sv.pb(i);
        }
    }
 
    //cerr<<u<<" "<<v<<"\n";
 
    int xx = solve(su, 0);
    int yy = solve(sv, 1);
    //cout<<xx<<" "<<yy<<"\n";
    answer(xx, yy);
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 2676 KB Output is correct
2 Correct 4 ms 2680 KB Output is correct
3 Correct 4 ms 2680 KB Output is correct
4 Correct 4 ms 2680 KB Output is correct
5 Correct 5 ms 2732 KB Output is correct
6 Correct 5 ms 2680 KB Output is correct
7 Correct 4 ms 2680 KB Output is correct
8 Correct 4 ms 2680 KB Output is correct
9 Correct 4 ms 2680 KB Output is correct
10 Correct 4 ms 2808 KB Output is correct
11 Correct 4 ms 2680 KB Output is correct
12 Correct 4 ms 2680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2812 KB Output is correct
2 Correct 26 ms 3812 KB Output is correct
3 Correct 233 ms 11528 KB Output is correct
4 Correct 234 ms 12140 KB Output is correct
5 Correct 235 ms 12140 KB Output is correct
6 Correct 228 ms 12148 KB Output is correct
7 Correct 223 ms 12124 KB Output is correct
8 Correct 223 ms 12140 KB Output is correct
9 Correct 206 ms 11528 KB Output is correct
10 Correct 199 ms 12136 KB Output is correct
11 Correct 251 ms 10640 KB Output is correct
12 Correct 195 ms 11236 KB Output is correct
13 Correct 236 ms 11548 KB Output is correct
14 Correct 231 ms 10920 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3704 KB Output is correct
2 Correct 38 ms 4504 KB Output is correct
3 Correct 57 ms 5492 KB Output is correct
4 Correct 152 ms 10668 KB Output is correct
5 Correct 156 ms 10748 KB Output is correct
6 Correct 155 ms 11372 KB Output is correct
7 Correct 204 ms 10968 KB Output is correct
8 Correct 180 ms 10764 KB Output is correct
9 Correct 179 ms 11280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2940 KB Output is correct
2 Correct 28 ms 3704 KB Output is correct
3 Correct 164 ms 10296 KB Output is correct
4 Correct 212 ms 11940 KB Output is correct
5 Correct 212 ms 11524 KB Output is correct
6 Correct 216 ms 12136 KB Output is correct
7 Correct 214 ms 11536 KB Output is correct
8 Correct 214 ms 11424 KB Output is correct
9 Correct 220 ms 11528 KB Output is correct
10 Correct 227 ms 11572 KB Output is correct
11 Correct 245 ms 11008 KB Output is correct
12 Correct 246 ms 11452 KB Output is correct
13 Correct 248 ms 11372 KB Output is correct
14 Correct 232 ms 10476 KB Output is correct
15 Correct 226 ms 12136 KB Output is correct
16 Correct 184 ms 12136 KB Output is correct
17 Correct 237 ms 10988 KB Output is correct
18 Correct 247 ms 10888 KB Output is correct
19 Correct 198 ms 11516 KB Output is correct
20 Correct 205 ms 11488 KB Output is correct
21 Correct 184 ms 12548 KB Output is correct
22 Correct 158 ms 12576 KB Output is correct
23 Correct 217 ms 11372 KB Output is correct
24 Correct 212 ms 11236 KB Output is correct
25 Correct 265 ms 11128 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 30 ms 3732 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 34 ms 3776 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -