Submission #139383

# Submission time Handle Problem Language Result Execution time Memory
139383 2019-07-31T15:33:52 Z fredbr Highway Tolls (IOI18_highway) C++17
0 / 100
401 ms 262148 KB
#include "highway.h"

#include <bits/stdc++.h>

using namespace std;

using ll = long long;

int const maxn = 90909;

struct Edge {
    int u, id;
};

vector<Edge> v[maxn];

vector<int> order;
vector<int> vt;

void dfs(int x, int p) {
    for (Edge e : v[x]) {
        if (e.u == p) continue;
        order.push_back(e.id);
        vt.push_back(x);
        dfs(e.u, x);
        vt.push_back(e.u);
        order.push_back(e.id);
    }
}

void find_pair(int n, vector<int> U, vector<int> V, int a, int b) {
    int m = U.size();

    for (int i = 0; i < m; i++) {
        v[U[i]].push_back(Edge{V[i], i});
        v[V[i]].push_back(Edge{U[i], i});
    }

    dfs(0, 0);

    ll total_cost = ask(vector<int>(m, 0));

    int l = 0, r = order.size();

    while (r-l > 1) {
        int mid = (l+r)/2;

        vector<int> q(m);
        for (int i = 0; i < mid; i++)
            q[order[i]]++;

        for (int& i : q) {
            if (i == 2) i = 1;
            else i = 0;
        }
        
        ll cost = ask(q);

        if (cost == total_cost) l = mid;
        else r = mid;
    }

    int old_l = l;

    l = 0, r = (int)order.size();

    while (r-l > 1) {
        int mid = (l+r)/2;

        vector<int> q(m);
        for (int i = mid; i < (int)order.size(); i++)
            q[order[i]]++;

        for (int& i : q) {
            if (i == 2) i = 1;
            else i = 0;
        }

        ll cost = ask(q);

        if (cost == total_cost) r = mid;
        else l = mid;
    }

    r = l;
    l = old_l;

    // for (int i : order) cout << i << " ";
    // cout << "\n";

    // cout << l << " " << r << "\n";
    vector<int> cnt(n);

    for (int i = l; i <= r; i++) {
        cnt[U[order[i]]]++;
        cnt[V[order[i]]]++;
    }

    a = -1, b = -1;

    for (int i = 0; i < n; i++) {
        if (cnt[i] == 1) {

            if (a == -1) a = i;
            else b= i;
        }
    }

    if (a > b) swap(a, b);
    answer(a, b);
}
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2344 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 2552 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 16 ms 3924 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 2472 KB Output is correct
2 Correct 19 ms 3168 KB Output is correct
3 Correct 148 ms 7860 KB Output is correct
4 Correct 167 ms 9016 KB Output is correct
5 Incorrect 196 ms 9060 KB Output is incorrect: {s, t} is wrong.
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 401 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 372 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -