Submission #1013339

#TimeUsernameProblemLanguageResultExecution timeMemory
1013339c2zi6Highway Tolls (IOI18_highway)C++14
51 / 100
286 ms262144 KiB
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define replr(i, a, b) for (int i = int(a); i <= int(b); ++i)
#define reprl(i, a, b) for (int i = int(a); i >= int(b); --i)
#define rep(i, n) for (int i = 0; i < int(n); ++i)
#define mkp(a, b) make_pair(a, b)
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<PII> VPI;
typedef vector<VI> VVI;
typedef vector<VVI> VVVI;
typedef vector<VPI> VVPI;
typedef pair<ll, ll> PLL;
typedef vector<ll> VL;
typedef vector<PLL> VPL;
typedef vector<VL> VVL;
typedef vector<VVL> VVVL;
typedef vector<VPL> VVPL;
template<class T> T setmax(T& a, T b) {if (a < b) return a = b; return a;}
template<class T> T setmin(T& a, T b) {if (a < b) return a; return a = b;}
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template<class T>
using indset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#include "highway.h"

int n, m;
VVPI gp;
VI depth;
VI parind;
VI par;

VI euler;
void dfs(int u = 0, int p = -1, int pind = -1) {
    if (u) euler.pb(u);
    parind[u] = pind;
    par[u] = p;
    for (auto[v, ind] : gp[u]) if (ind != pind) {
        depth[v] = depth[u]+1;
        dfs(v, u, ind);
    }
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B) {
    n = N;
    m = U.size();
    gp = VVPI(n);
    rep(i, m) {
        gp[U[i]].pb({V[i], i});
        gp[V[i]].pb({U[i], i});
    }
    depth = parind = par = VI(n);
    euler = VI();
    dfs();
    ll base = ask(VI(m));
    int d = base/A;

    int s;
    if (true) {
        /*searching for value of s*/
        auto f = [&](int x) {
            VI W(m);
            replr(i, 0, x) W[parind[euler[i]]] = true;
            return (ask(W)-base)/(B-A);
        };
        int l = -1, r = m-1;
        while (l+1 < r) {
            int m = (l + r) / 2;
            if (f(m) < d) l = m;
            else r = m;
        }
        s = euler[r];
    }
    /*cout << "FIRST NODE: " << s << endl;*/
    depth = parind = par = VI(n);
    euler = VI();
    dfs(s);
    int t;
    if (true) {
        /*searching for value of t*/
        VI b;
        rep(u, n) if (depth[u] == d) b.pb(u);
        auto f = [&](int x) {
            VI W(m);
            replr(i, 0, x) W[parind[b[i]]] = true;
            return ask(W) > base;
        };
        int l = -1, r = b.size()-1;
        while (l + 1 < r) {
            int m = (l + r) / 2;
            if (f(m)) r = m;
            else l = m;
        }
        t = b[r];
    }
    /*cout << "SECOND NODE: " << t << endl;*/
    answer(s, t);
}

/*ask(VI w);*/
/*answer(int s, int t)*/

Compilation message (stderr)

highway.cpp: In function 'void dfs(int, int, int)':
highway.cpp:45:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   45 |     for (auto[v, ind] : gp[u]) if (ind != pind) {
      |              ^
#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...