Submission #286286

# Submission time Handle Problem Language Result Execution time Memory
286286 2020-08-30T09:16:44 Z dolphingarlic Highway Tolls (IOI18_highway) C++14
0 / 100
246 ms 262148 KB
#include "highway.h"

#include <bits/stdc++.h>
using namespace std;

vector<int> W;
vector<pair<int, int>> graph[90000], ord;

void dfs(int node, int parent = -1) {
    for (pair<int, int> i : graph[node]) if (i.first != parent) {
        ord.push_back(i);
        dfs(i.first, node);
    }
}

void find_pair(int N, vector<int> U, vector<int> V, int A, int B) {
    int M = int(U.size());
    if (M != N - 1) answer(0, 0);

    for (int i = 0; i < N; i++) graph[i].clear();
    ord.clear();
    for (int i = 0; i < M; i++) {
        graph[U[i]].push_back({V[i], i});
        graph[V[i]].push_back({U[i], i});
    }
    ord.push_back({0, -1});
    dfs(0);

    W.resize(M);
    for (int i = 0; i < M; i++) W[i] = 0;
    long long path_len = ask(W) / A;

    int l = 0, r = M;
    while (l != r) {
        int mid = (l + r) / 2;
        for (int i = 1; i <= mid; i++) W[ord[i].second] = 1;
        for (int i = mid + 1; i < M; i++) W[ord[i].second] = 0;
        long long dist = ask(W);
        if (dist == path_len * B) r = mid;
        else l = mid + 1;
    }
    cout << l << endl;
    int T = ord[l].first;

    ord.clear();
    ord.push_back({0, -1});
    dfs(T);

    l = 0, r = M;
    while (l != r) {
        int mid = (l + r) / 2;
        for (int i = 1; i <= mid; i++) W[ord[i].second] = 1;
        for (int i = mid + 1; i < M; i++) W[ord[i].second] = 0;
        long long dist = ask(W);
        if (dist == path_len * B) r = mid;
        else l = mid + 1;
    }
    int S = ord[l].first;

    answer(S, T);
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2432 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 4 ms 2432 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 13 ms 4096 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 2432 KB DO NOT PRINT ANYTHING TO STANDARD OUTPUT
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 246 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 220 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -