Submission #250306

#TimeUsernameProblemLanguageResultExecution timeMemory
250306Osama_AlkhodairyHighway Tolls (IOI18_highway)C++17
51 / 100
3026 ms13336 KiB
#include <bits/stdc++.h>
#include "highway.h"
//~ #include "grader.cpp"
using namespace std;
#define ll long long

int n, m;
vector <pair <int, int> > es, g[90001];
ll light;
int dist;

int find(int root){
    vector <bool> vis(n);
    queue <int> ready;
    vector <int> depth(n);
    ready.push(root);
    vector <int> nodes;
    while(ready.size()){
        int node = ready.front();
        ready.pop();
        nodes.push_back(node);
        vis[node] = 1;
        for(auto &i : g[node]){
            if(vis[i.first]) continue;
            depth[i.first] = depth[node] + 1;
            ready.push(i.first);
        }
    }
    reverse(nodes.begin(), nodes.end());
    vis.assign(m, 0);
    vector <int> edges;
    for(auto &i : nodes){
        for(auto &j : g[i]){
            if(vis[j.second]) continue;
            vis[j.second] = 1;
            edges.push_back(j.second);
        }
    }
    int l = 0, r = m - 1;
    while(max(depth[es[edges[l]].first], depth[es[edges[l]].second]) < dist / 2){
        l++;
    }
    while(l <= r){
        int mid = (l + r) / 2;
        vector <int> check(m);
        for(int i = 0 ; i <= mid ; i++){
            check[edges[i]] = 1;
        }
        if(ask(check) != light) r = mid - 1;
        else l = mid + 1;
    }
    auto edge = es[edges[l]];
    if(depth[edge.first] > depth[edge.second]) return edge.first;
    return edge.second;
}
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++){
        g[u[i]].push_back(make_pair(v[i], i));
        g[v[i]].push_back(make_pair(u[i], i));
        es.push_back(make_pair(u[i], v[i]));
    }
    light = ask(vector <int>(m, 0));
    dist = light / a;
    int l = 0, r = m - 1;
    while(l <= r){
        int mid = (l + r) / 2;
        vector <int> check(m);
        for(int i = 0 ; i <= mid ; i++){
            check[i] = 1;
        }
        if(ask(check) != light) r = mid - 1;
        else l = mid + 1;
    }
    int root = es[l].first;
    int s = find(root);
    int t = find(s);
    answer(s, t);
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...