Submission #155661

# Submission time Handle Problem Language Result Execution time Memory
155661 2019-09-29T15:28:42 Z rama_pang Highway Tolls (IOI18_highway) C++14
0 / 100
392 ms 262148 KB
#include "highway.h"
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint MAXN = 150005;

lint N, M, A, B;
vector<int> G[MAXN];
lint dist[MAXN];
struct edge {
    int u, v, id;
    edge(int uu, int vv, int idd): u(uu), v(vv), id(idd) { }
    bool operator < (const edge &o) {
        return dist[u] < dist[o.u];
    }
};
vector<edge> E;

void dfs(int n, int p, int d) {
    dist[n] = d;
    for (auto &i : G[n]) if (i != p) {
        dfs(i, n, d + 1);
    }
}

void find_pair(int _N, vector<int> U, vector<int> V, int _A, int _B) {
    N = _N, A = _A, B = _B, M = U.size();
    for (int i = 0; i < M; i++) {
        G[U[i]].emplace_back(V[i]);
        G[V[i]].emplace_back(U[i]);
        E.emplace_back(U[i], V[i], i);
    }
    dfs(0, -1, 0);
    for (int i = 0; i < M; i++) {
        if (dist[E[i].u] > dist[E[i].v]) swap(E[i].u, E[i].v);
    }
    sort(E.begin(), E.end());
    lint le = 0, ri = M - 1;
    lint ans = (dist[E.back().u] > dist[E.back().v])? E.back().u : E.back().v;
    vector<int> guess(M, 0);
    lint DA = ask(guess);
    lint DB = (DA / A) * B;
    while (le <= ri) {
        guess.assign(M, 0);
        lint mid = (le + ri) / 2;
        for (int i = 0; i <= mid; i++) guess[E[i].id] = 1;
        int check = ask(guess);
        // cout << le << " " << ri << " " << check << "\n";
        if (check > DB) {
            // ans = mid;
            ri = mid - 1;
        } else {
            ans = mid;
            le = mid + 1;
        }
    }
    cout << ans << "\n";
    ans = (dist[E[ans].u] * A == DA)? E[ans].u : E[ans].v;
    answer(0, ans);
}

/*

4 4 1 3 1 3
0 1
0 2
0 3
1 2

4 3 1 3 0 3
0 1
0 2
0 3

4 3 1 3 0 2
0 1
0 3
1 2


*/
# Verdict Execution time Memory Grader output
1 Incorrect 5 ms 3832 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 3832 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 22 ms 4984 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 3832 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 392 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 371 ms 262144 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -