Submission #1081983

# Submission time Handle Problem Language Result Execution time Memory
1081983 2024-08-30T13:53:18 Z vladilius Highway Tolls (IOI18_highway) C++17
0 / 100
13 ms 2904 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define pb push_back
#define ff first
#define ss second
 
void find_pair(int n, vector<int> U, vector<int> V, int A, int B){
    int m = (int) U.size();
    vector<pii> g[n + 1];
    for (int i = 0; i < m; i++){
        U[i]++; V[i]++;
        g[U[i]].pb({V[i], i});
        g[V[i]].pb({U[i], i});
    }
    
    vector<int> w(m);
 
    ll nl = ask(w);
    int l = 0, r = m - 1;
    while (l + 1 < r){
        int k = (l + r) / 2;
        fill(w.begin(), w.end(), 0);
        for (int i = k + 1; i < m; i++) w[i] = 1;
        if (ask(w) == nl){
            r = k;
        }
        else {
            l = k + 1;
        }
    }
    
    fill(w.begin(), w.end(), 0);
    for (int i = l + 1; i < m; i++) w[i] = 1;
    if (ask(w) == nl){
        r = l;
    }
    int x = r;
 
    vector<bool> used(n + 1);
    vector<int> ed = {x};
    queue<int> q;
    q.push(V[x]);
    q.push(U[x]);
    used[V[x]] = used[U[x]] = 1;
    while (!q.empty()){
        int f = q.front(); q.pop();
        for (auto [i, j]: g[f]){
            if (used[i] || j == x) continue;
            used[i] = 1;
            q.push(i);
            ed.pb(j);
        }
    }
    
    fill(w.begin(), w.end(), 1);
    
    auto cl = [&](){
        for (int i: ed) w[i] = 0;
    };
    
    cl();
    vector<pii> t[n + 1];
    for (int i: ed){
        t[U[i]].pb({V[i], i});
        t[V[i]].pb({U[i], i});
    }
    
    vector<int> d(n + 1), p(n + 1), pe(n + 1);
    function<void(int, int, vector<int>&, vector<int>&)> dfs = [&](int v, int pr, vector<int>& ed, vector<int>& q){
        q.pb(v);
        p[v] = pr;
        for (auto [i, j]: t[v]){
            if (i == pr || j == x) continue;
            d[i] = d[v] + 1;
            pe[i] = j;
            ed.pb(j);
            dfs(i, v, ed, q);
        }
    };
    
    vector<int> d1, d2, t1, t2;
    dfs(U[x], 0, d1, t1);
    dfs(V[x], 0, d2, t2);
    
    int dist = (int) (ask(w) / A);
 
    auto cmp = [&](int x, int y){
        return (d[x] < d[y]);
    };
    
    auto solve = [&](int v, vector<int>& x1, vector<int>& x2, vector<int> vv){
        sort(vv.begin(), vv.end(), cmp);
        
        int ds = (int) ((ask(w) + B - A - 1LL * dist * B) / (A - B));
        
        auto check = [&](int k){
            cl();
            for (int i = 0; i <= k; i++){
                if (vv[i] != v) w[pe[vv[i]]] = 1;
            }
            return (ask(w) == (1LL * B * ds + 1LL * A * (dist - ds)));
        };
        
        int l = 0, r = (int) vv.size() - 1;
        while (l + 1 < r){
            int k = (l + r) / 2;
            if (check(k)){
                r = k;
            }
            else {
                l = k + 1;
            }
        }
        
        if (check(l)) r = l;
        
        return (vv[r] - 1);
    };
    
    answer(solve(U[x], d1, d2, t1), solve(V[x], d2, d1, t2));
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 9 ms 2904 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 600 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 2040 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 11 ms 2392 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -