Submission #220131

# Submission time Handle Problem Language Result Execution time Memory
220131 2020-04-07T05:54:56 Z IgorI Highway Tolls (IOI18_highway) C++17
69 / 100
327 ms 39560 KB
#ifdef LOCAL

#else
#include <highway.h>
#endif // LOCAL

#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

#ifdef LOCAL
void answer(int s, int t)
{
    cout << s << " " << t << endl;
    exit(0);
}

long long ask(vector<int> w)
{
    long long res;
    for (int i = 0; i < w.size(); i++)
    {
        cout << w[i] << " ";
    }
    cout << endl;
    cin >> res;
    return res;
}
#endif // LOCAL

const int N = 200000;
int n, m, a, b;
vector<vector<int> > g;
vector<int> u, v;
long long Dist;
int linker;

struct tr{
    int id, ver, dist;
};

bool comp(tr a, tr b)
{
    return a.dist < b.dist;
}

map<vector<int>, long long> mm;

long long myask(vector<int> w)
{
    if (mm.find(w) != mm.end()) return mm[w];
    return mm[w] = ask(w);
}

vector<tr> bfs(int root, vector<int> use)
{
    vector<int> curdist(n, N);
    vector<int> ok(m);
    for (int i = 0; i < use.size(); i++) ok[use[i]] = 1;
    vector<int> q = {root};
    curdist[root] = 0;
    vector<tr> ans = {{linker, root, 0}};
    for (int i = 0; i < q.size(); i++)
    {
        int x = q[i];
        for (auto id : g[x])
        {
            int y = u[id] + v[id] - x;
            if (ok[id] && curdist[y] == N)
            {
                curdist[y] = curdist[x] + 1;
                q.push_back(y);
                ans.push_back({id, y, curdist[y]});
            }
        }
    }
    return ans;
}

int solve_for_tree(int root, vector<int> edges, vector<int> others)
{
    vector<tr> kek = bfs(root, edges);
    sort(kek.begin(), kek.end(), comp);
    int l = -1, r = kek.size() + 1;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        vector<int> w(m, 1);
        for (auto it : others) w[it] = 0;
        for (int i = 0; i <= mid; i++) w[kek[i].id] = 0;
        long long si = myask(w);
        if (si == Dist * a)
            r = mid;
        else
            l = mid;
    }
    #ifdef LOCAL
        cerr << kek.size() << "\n";
        for (int i = 0; i < kek.size(); i++)
        {
            cerr << kek[i].id << " " << kek[i].ver << " " << kek[i].dist << "\n";
        }
    #endif
    vector<int> w1(m, 1), w2(m, 1);
    for (auto it : others) w1[it] = 0, w2[it] = 0;
    for (int i = 0; i < r; i++) w1[kek[i].id] = 0;
    for (int i = 0; i <= r; i++) w2[kek[i].id] = 0;
    long long s1 = myask(w1), s2 = myask(w2);
    if (s2 != Dist * a) exit(1);
    return kek[r].ver;
}

void find_pair(int n0, vector<int> v0, vector<int> u0, int a0, int b0)
{
    n = n0;
    a = a0;
    b = b0;
    m = v0.size();
    g.resize(n0);
    v = v0, u = u0;
    for (int i = 0; i < m; i++)
    {
        g[v[i]].push_back(i);
        g[u[i]].push_back(i);
    }
    vector<int> q0(m);
    Dist = myask(q0) / a;

    int l = -1, r = m + 1;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        vector<int> q(m, 1);
        for (int i = l; i < mid; i++)
        {
            q[i] = 0;
        }
        long long res = myask(q);
        if (res == Dist * b)
            l = mid;
        else
            r = mid;
    }
    int V = v[l];
    int U = u[l];
    linker = l;
    vector<int> distV(n, N), distU(n, N), fromV(n), fromU(n);
    distV[V] = 0, distU[U] = 0;
    vector<int> qV = {V};
    for (int i = 0; i < qV.size(); i++)
    {
        int x = qV[i];
        for (auto id : g[x])
        {
            int y = v[id] + u[id] - x;
            if (distV[y] == N)
            {
                distV[y] = distV[x] + 1;
                qV.push_back(y);
                fromV[y] = id;
            }
        }
    }
    vector<int> qU = {U};
    for (int i = 0; i < qU.size(); i++)
    {
        int x = qU[i];
        for (auto id : g[x])
        {
            int y = v[id] + u[id] - x;
            if (distU[y] == N)
            {
                distU[y] = distU[x] + 1;
                qU.push_back(y);
                fromU[y] = id;
            }
        }
    }
    vector<int> vecV, vecU;
    for (int i = 0; i < n; i++)
    {
        if (i != U) if (distU[i] <= distV[i]) vecU.push_back(fromU[i]);
        if (i != V) if (distV[i] < distU[i]) vecV.push_back(fromV[i]);
    }
    #ifdef LOCAL
        cerr << "determined : " << V << " " << U << "\n";
        cerr << "tree (V) : ";
        for (auto id : vecV) cerr << v[id] << " " << u[id] << "\n";
        cerr << "\n";
        cerr << "tree (U) : ";
        for (auto id : vecU) cerr << v[id] << " " << u[id] << "\n";
        cerr << "\n";
    #endif // LOCAL
    if (Dist == 1)
    {
        answer(V, U);
        exit(0);
    }
    int s = solve_for_tree(V, vecV, vecU);
    cerr << "determined s = " << s << "\n";
    int t = solve_for_tree(U, vecU, vecV);
    cerr << "determined t = " << t << "\n";

    //vector<int> all;
    //for (int i = 0; i < m; i++) all.push_back(i);
    //vector<tr> kek = bfs(s, all);
    //int tt = 0;
    //for (int i = 0; i < kek.size(); i++) if (kek[i].ver == t) tt = (kek[i].dist == Dist);
    //if (tt == 0)
    //    exit(1);

    answer(s, t);
}

#ifdef LOCAL
signed main()
{
    int n, m, a, b;
    cin >> n >> m >> a >> b;
    vector<int> v(m), u(m);
    for (int i = 0; i < m; i++)
    {
        cin >> v[i] >> u[i];
    }
    find_pair(n, v, u, a, b);
}
#endif // LOCAL

Compilation message

highway.cpp: In function 'std::vector<tr> bfs(int, std::vector<int>)':
highway.cpp:62:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < use.size(); i++) ok[use[i]] = 1;
                     ~~^~~~~~~~~~~~
highway.cpp:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < q.size(); i++)
                     ~~^~~~~~~~~~
highway.cpp: In function 'int solve_for_tree(int, std::vector<int>, std::vector<int>)':
highway.cpp:111:15: warning: unused variable 's1' [-Wunused-variable]
     long long s1 = myask(w1), s2 = myask(w2);
               ^~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:153:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < qV.size(); i++)
                     ~~^~~~~~~~~~~
highway.cpp:168:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < qU.size(); i++)
                     ~~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 388 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 288 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 492 KB Output is correct
2 Correct 19 ms 2928 KB Output is correct
3 Correct 198 ms 25792 KB Output is correct
4 Correct 194 ms 28636 KB Output is correct
5 Correct 188 ms 28212 KB Output is correct
6 Correct 180 ms 25888 KB Output is correct
7 Correct 195 ms 28372 KB Output is correct
8 Correct 194 ms 28660 KB Output is correct
9 Correct 168 ms 25500 KB Output is correct
10 Correct 189 ms 27152 KB Output is correct
11 Correct 220 ms 29716 KB Output is correct
12 Correct 208 ms 29472 KB Output is correct
13 Correct 197 ms 28584 KB Output is correct
14 Correct 199 ms 27768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 3244 KB Output is correct
2 Correct 36 ms 6276 KB Output is correct
3 Correct 62 ms 9148 KB Output is correct
4 Correct 157 ms 29668 KB Output is correct
5 Correct 157 ms 30480 KB Output is correct
6 Correct 173 ms 29832 KB Output is correct
7 Correct 170 ms 28164 KB Output is correct
8 Correct 154 ms 30252 KB Output is correct
9 Correct 166 ms 29428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 512 KB Output is correct
2 Correct 22 ms 3320 KB Output is correct
3 Correct 127 ms 20728 KB Output is correct
4 Correct 179 ms 26212 KB Output is correct
5 Correct 202 ms 25416 KB Output is correct
6 Correct 196 ms 25532 KB Output is correct
7 Correct 188 ms 25056 KB Output is correct
8 Correct 193 ms 24652 KB Output is correct
9 Correct 208 ms 28632 KB Output is correct
10 Correct 209 ms 27968 KB Output is correct
11 Correct 230 ms 27792 KB Output is correct
12 Correct 221 ms 28872 KB Output is correct
13 Correct 210 ms 28688 KB Output is correct
14 Correct 220 ms 29248 KB Output is correct
15 Correct 187 ms 24780 KB Output is correct
16 Correct 189 ms 25868 KB Output is correct
17 Correct 225 ms 28108 KB Output is correct
18 Correct 221 ms 27816 KB Output is correct
19 Correct 203 ms 25184 KB Output is correct
20 Correct 227 ms 29436 KB Output is correct
21 Correct 152 ms 25332 KB Output is correct
22 Correct 165 ms 25308 KB Output is correct
23 Correct 198 ms 30408 KB Output is correct
24 Correct 206 ms 29928 KB Output is correct
25 Correct 241 ms 28040 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 24 ms 3628 KB Output is correct
2 Correct 24 ms 3528 KB Output is correct
3 Correct 245 ms 31316 KB Output is correct
4 Correct 254 ms 33672 KB Output is correct
5 Correct 327 ms 39560 KB Output is correct
6 Correct 301 ms 39052 KB Output is correct
7 Correct 296 ms 38944 KB Output is correct
8 Correct 307 ms 39360 KB Output is correct
9 Correct 196 ms 27504 KB Output is correct
10 Correct 180 ms 16772 KB Output is correct
11 Correct 226 ms 28620 KB Output is correct
12 Correct 297 ms 38372 KB Output is correct
13 Correct 283 ms 37648 KB Output is correct
14 Correct 303 ms 39388 KB Output is correct
15 Correct 308 ms 39084 KB Output is correct
16 Correct 253 ms 34000 KB Output is correct
17 Correct 191 ms 29344 KB Output is correct
18 Correct 206 ms 29140 KB Output is correct
19 Correct 195 ms 29668 KB Output is correct
20 Correct 177 ms 29628 KB Output is correct
21 Correct 311 ms 38524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 3448 KB Output is correct
2 Correct 28 ms 3532 KB Output is correct
3 Correct 249 ms 32520 KB Output is correct
4 Correct 254 ms 31624 KB Output is correct
5 Correct 249 ms 34584 KB Output is correct
6 Runtime error 260 ms 31540 KB Execution failed because the return code was nonzero
7 Halted 0 ms 0 KB -