Submission #1237394

#TimeUsernameProblemLanguageResultExecution timeMemory
1237394TimoshHighway Tolls (IOI18_highway)C++20
12 / 100
317 ms327680 KiB
#include "bits/stdc++.h"
#include "highway.h"

using namespace std;

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
    int M = U.size();
    vector<int> d(N), w(M);
    int D = ask(w);
    vector<vector<int>> g(N);
    for (int i = 0; i < M; i++)
    {
        g[U[i]].push_back(V[i]);
        g[V[i]].push_back(U[i]);
    }
    auto dfs = [&](auto dfs, int node, int par) -> void
    {
        for (auto &x : g[node])
        {
            if (x == par)
                continue;
            d[x] = d[node] + 1;
            dfs(dfs, x, node);
        }
    };
    dfs(dfs, 0, -1);
    int a = 0;
    int l = 0, r = N;
    while (l <= r)
    {
        int m = (l + r) / 2;
        for (int i = 0; i < M; i++)
            w[i] = max(d[U[i]], d[V[i]]) > m;
        int x = ask(w);
        if (x == D)
            r = m - 1;
        else
            a = m, l = m + 1;
    }
    a++;
    vector<int> cands;
    for (int i = 0; i < M; i++)
        if (max(d[U[i]], d[V[i]]) == a)
            cands.push_back(i);
    while (cands.size() > 1)
    {
        int m = cands.size() / 2;
        for (auto &i : w)
            i = 0;
        for (int j = 0; j < m; j++)
            w[cands[j]] = 1;
        int x = ask(w);
        vector<int> R;
        while (cands.size() > m)
            R.push_back(cands.back()), cands.pop_back();
        if (x == D)
            cands = R;
    }
    int b = (d[V[cands[0]]] > d[U[cands[0]]] ? V[cands[0]] : U[cands[0]]);
    answer(0, b);
}
#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...