Submission #139353

# Submission time Handle Problem Language Result Execution time Memory
139353 2019-07-31T15:09:17 Z fredbr Highway Tolls (IOI18_highway) C++17
0 / 100
378 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;

void dfs(int x, int p) {
    for (Edge e : v[x]) {
        if (e.u == p) continue;
        order.push_back(e.id);
        dfs(e.u, x);
        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]] = 1;

        ll cost = ask(q);

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

    int old_l = l;

    l = -1, r = (int)order.size()-1;

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

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

        ll cost = ask(q);

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

    l = old_l;

    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 (i != U[order[l]] and i != V[order[l]] and
                i != U[order[r]] and i != V[order[r]]) continue;

            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 21 ms 3752 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2556 KB Output is incorrect: {s, t} is wrong.
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 378 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 345 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -