답안 #403962

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
403962 2021-05-13T15:54:24 Z idk321 통행료 (IOI18_highway) C++11
51 / 100
450 ms 262148 KB
#include "highway.h"

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


int n, m, a, b;
vector<int> u;
vector<int> v;

const int N = 90000;


int edges;
ll minCost;
vector<int> adj[N];
vector<int> adj2[N];




void addInSubtree(int node, int par, vector<int>& w)
{
    for (int i : adj2[node])
    {
         w[i] = 1;
    }

    for (int next : adj[node])
    {
        if (next == par) continue;
        addInSubtree(next, node, w);
    }
}

ll subtreeCost(int node, int par)
{
    vector<int> w(m);
    addInSubtree(node, par, w);
    return ask(w);
}

void addEnds(int node, int par, int needed, int ch, vector<int>& possEnds)
{
    if (ch == needed)
    {
        possEnds.push_back(node);
        return;
    }

    for (int next : adj[node])
    {
        if (next == par) continue;
        addEnds(next, node, needed, ch + 1, possEnds);
    }
}

int getIn(vector<int>& nodes)
{
    int from = 0;
    int to = nodes.size() - 1;
    int res = -1;
    vector<int> w(m);
    while (from <= to)
    {
        int mid = (from + to) / 2;
        w.clear();
        w.resize(m);
        for (int i = 0; i <= mid; i++)
        {
            for (int j : adj2[nodes[i]])
            {
                w[j] = 1;
            }
        }

        ll cur = ask(w);
        if (cur == minCost)
        {
            from = mid + 1;
        } else
        {
            res = nodes[mid];
            to = mid - 1;
        }
    }

    return res;
}

int getSubtreeEnd(int node, int par)
{
    ll cost = subtreeCost(node, par);
    int needed = (cost - minCost) / (b - a);
    vector<int> possEnds;
    addEnds(node, par, needed, 1, possEnds);

    int res = getIn(possEnds);
    return res;
}

void find_pair(int N, std::vector<int> U, std::vector<int> V, int A, int B)
{
    n = N;
    a = A;
    b = B;
    u = U;
    v = V;
    m = v.size();

    for (int i = 0; i < m; i++)
    {
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
        adj2[u[i]].push_back(i);
        adj2[v[i]].push_back(i);
    }

    vector<int> w(m);
    minCost = ask(w);
    edges = minCost / a;

    int from = 0;
    int to = n - 2;
    int res = -1;
    while (from <= to)
    {
        int mid = (from + to) / 2;
        w.clear();
        w.resize(m);
        for (int i = 0; i <= mid; i++)
        {
            w[i] = true;
        }

        ll cur = ask(w);
        if (cur == minCost)
        {
            from = mid + 1;
        } else
        {
            res = mid;
            to = mid - 1;
        }
    }

    int x = u[res];
    int y = v[res];
    int rx = getSubtreeEnd(x, y);
    int ry = getSubtreeEnd(y, x);
    answer(rx, ry);
}


/*
15 14 1 2 0 3
0 4
4 5
4 3
12 3
3 7
7 8
8 11
8 10
6 13
6 14
6 9
3 6
2 3
10 1
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 4424 KB Output is correct
2 Correct 4 ms 4424 KB Output is correct
3 Correct 3 ms 4424 KB Output is correct
4 Correct 3 ms 4424 KB Output is correct
5 Correct 3 ms 4424 KB Output is correct
6 Correct 3 ms 4424 KB Output is correct
7 Correct 3 ms 4424 KB Output is correct
8 Correct 3 ms 4424 KB Output is correct
9 Correct 3 ms 4424 KB Output is correct
10 Correct 3 ms 4424 KB Output is correct
11 Correct 3 ms 4424 KB Output is correct
12 Correct 3 ms 4424 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4552 KB Output is correct
2 Correct 20 ms 5380 KB Output is correct
3 Correct 177 ms 13276 KB Output is correct
4 Correct 169 ms 13304 KB Output is correct
5 Correct 201 ms 13440 KB Output is correct
6 Correct 165 ms 13200 KB Output is correct
7 Correct 191 ms 13296 KB Output is correct
8 Correct 154 ms 13276 KB Output is correct
9 Correct 178 ms 13188 KB Output is correct
10 Correct 213 ms 13300 KB Output is correct
11 Correct 185 ms 13776 KB Output is correct
12 Correct 163 ms 14328 KB Output is correct
13 Correct 192 ms 14004 KB Output is correct
14 Correct 177 ms 14048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 5832 KB Output is correct
2 Correct 28 ms 7060 KB Output is correct
3 Correct 48 ms 8524 KB Output is correct
4 Correct 148 ms 15516 KB Output is correct
5 Correct 146 ms 15576 KB Output is correct
6 Correct 105 ms 17408 KB Output is correct
7 Correct 106 ms 16968 KB Output is correct
8 Correct 161 ms 16048 KB Output is correct
9 Correct 105 ms 16096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4616 KB Output is correct
2 Correct 21 ms 5440 KB Output is correct
3 Correct 129 ms 11192 KB Output is correct
4 Correct 170 ms 13236 KB Output is correct
5 Correct 170 ms 13164 KB Output is correct
6 Correct 142 ms 13164 KB Output is correct
7 Correct 185 ms 13076 KB Output is correct
8 Correct 188 ms 13336 KB Output is correct
9 Correct 209 ms 13276 KB Output is correct
10 Correct 174 ms 13276 KB Output is correct
11 Correct 186 ms 13760 KB Output is correct
12 Correct 195 ms 14292 KB Output is correct
13 Correct 163 ms 14156 KB Output is correct
14 Correct 163 ms 14124 KB Output is correct
15 Correct 201 ms 13084 KB Output is correct
16 Correct 186 ms 13188 KB Output is correct
17 Correct 209 ms 13848 KB Output is correct
18 Correct 155 ms 14280 KB Output is correct
19 Correct 224 ms 13176 KB Output is correct
20 Correct 152 ms 14508 KB Output is correct
21 Correct 196 ms 14196 KB Output is correct
22 Correct 163 ms 14204 KB Output is correct
23 Correct 184 ms 14260 KB Output is correct
24 Correct 202 ms 14684 KB Output is correct
25 Correct 214 ms 19224 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 450 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 347 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -