Submission #220140

# Submission time Handle Problem Language Result Execution time Memory
220140 2020-04-07T06:10:03 Z IgorI Highway Tolls (IOI18_highway) C++17
100 / 100
260 ms 15748 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;
}

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 = ask(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
    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 = ask(q0) / a;

    int l = -1, r = m - 1;
    while (l + 1 < r)
    {
        int mid = (l + r) / 2;
        vector<int> q(m, 0);
        for (int i = 0; i <= mid; i++)
        {
            q[i] = 1;
        }
        long long res = ask(q);
        if (res != Dist * a)
            r = mid;
        else
            l = mid;
    }
    int V = v[r];
    int U = u[r];
    linker = r;
    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
    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";
    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:54: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:58:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < q.size(); i++)
                     ~~^~~~~~~~~~
highway.cpp: In function 'void find_pair(int, std::vector<int>, std::vector<int>, int, int)':
highway.cpp:139:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < qV.size(); i++)
                     ~~^~~~~~~~~~~
highway.cpp:154: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 384 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 384 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 512 KB Output is correct
2 Correct 18 ms 1920 KB Output is correct
3 Correct 168 ms 14060 KB Output is correct
4 Correct 184 ms 14076 KB Output is correct
5 Correct 184 ms 14012 KB Output is correct
6 Correct 205 ms 14060 KB Output is correct
7 Correct 186 ms 14040 KB Output is correct
8 Correct 172 ms 13988 KB Output is correct
9 Correct 160 ms 14088 KB Output is correct
10 Correct 172 ms 14020 KB Output is correct
11 Correct 187 ms 12960 KB Output is correct
12 Correct 194 ms 13956 KB Output is correct
13 Correct 219 ms 13892 KB Output is correct
14 Correct 189 ms 13832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 1920 KB Output is correct
2 Correct 31 ms 3276 KB Output is correct
3 Correct 50 ms 4620 KB Output is correct
4 Correct 131 ms 13280 KB Output is correct
5 Correct 137 ms 13256 KB Output is correct
6 Correct 142 ms 14096 KB Output is correct
7 Correct 133 ms 13916 KB Output is correct
8 Correct 133 ms 13172 KB Output is correct
9 Correct 137 ms 14064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 460 KB Output is correct
2 Correct 22 ms 1792 KB Output is correct
3 Correct 128 ms 11548 KB Output is correct
4 Correct 165 ms 14024 KB Output is correct
5 Correct 162 ms 14040 KB Output is correct
6 Correct 160 ms 14056 KB Output is correct
7 Correct 162 ms 14048 KB Output is correct
8 Correct 161 ms 14084 KB Output is correct
9 Correct 179 ms 14004 KB Output is correct
10 Correct 176 ms 14088 KB Output is correct
11 Correct 183 ms 13828 KB Output is correct
12 Correct 184 ms 13828 KB Output is correct
13 Correct 196 ms 13960 KB Output is correct
14 Correct 194 ms 12808 KB Output is correct
15 Correct 158 ms 14036 KB Output is correct
16 Correct 168 ms 14068 KB Output is correct
17 Correct 188 ms 13760 KB Output is correct
18 Correct 174 ms 13980 KB Output is correct
19 Correct 166 ms 14008 KB Output is correct
20 Correct 184 ms 13832 KB Output is correct
21 Correct 130 ms 14320 KB Output is correct
22 Correct 131 ms 14348 KB Output is correct
23 Correct 143 ms 13424 KB Output is correct
24 Correct 159 ms 13508 KB Output is correct
25 Correct 185 ms 13960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 2040 KB Output is correct
2 Correct 21 ms 2040 KB Output is correct
3 Correct 192 ms 14676 KB Output is correct
4 Correct 215 ms 13828 KB Output is correct
5 Correct 239 ms 15748 KB Output is correct
6 Correct 246 ms 15700 KB Output is correct
7 Correct 248 ms 15644 KB Output is correct
8 Correct 247 ms 14756 KB Output is correct
9 Correct 169 ms 8992 KB Output is correct
10 Correct 178 ms 8932 KB Output is correct
11 Correct 185 ms 10444 KB Output is correct
12 Correct 233 ms 13148 KB Output is correct
13 Correct 238 ms 14076 KB Output is correct
14 Correct 258 ms 14576 KB Output is correct
15 Correct 250 ms 14560 KB Output is correct
16 Correct 193 ms 9984 KB Output is correct
17 Correct 144 ms 14344 KB Output is correct
18 Correct 150 ms 14492 KB Output is correct
19 Correct 170 ms 14464 KB Output is correct
20 Correct 154 ms 14436 KB Output is correct
21 Correct 254 ms 15588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 20 ms 1840 KB Output is correct
2 Correct 22 ms 2040 KB Output is correct
3 Correct 205 ms 13696 KB Output is correct
4 Correct 213 ms 14804 KB Output is correct
5 Correct 211 ms 15028 KB Output is correct
6 Correct 246 ms 14720 KB Output is correct
7 Correct 192 ms 14572 KB Output is correct
8 Correct 193 ms 14840 KB Output is correct
9 Correct 222 ms 14092 KB Output is correct
10 Correct 247 ms 15728 KB Output is correct
11 Correct 250 ms 14768 KB Output is correct
12 Correct 246 ms 14708 KB Output is correct
13 Correct 174 ms 10424 KB Output is correct
14 Correct 171 ms 9052 KB Output is correct
15 Correct 168 ms 10336 KB Output is correct
16 Correct 170 ms 8924 KB Output is correct
17 Correct 175 ms 10392 KB Output is correct
18 Correct 175 ms 8908 KB Output is correct
19 Correct 239 ms 13072 KB Output is correct
20 Correct 244 ms 13916 KB Output is correct
21 Correct 245 ms 14824 KB Output is correct
22 Correct 245 ms 14496 KB Output is correct
23 Correct 249 ms 14748 KB Output is correct
24 Correct 246 ms 14484 KB Output is correct
25 Correct 248 ms 14504 KB Output is correct
26 Correct 252 ms 14520 KB Output is correct
27 Correct 144 ms 14412 KB Output is correct
28 Correct 147 ms 14492 KB Output is correct
29 Correct 152 ms 14588 KB Output is correct
30 Correct 145 ms 14540 KB Output is correct
31 Correct 155 ms 14316 KB Output is correct
32 Correct 157 ms 14400 KB Output is correct
33 Correct 159 ms 14552 KB Output is correct
34 Correct 150 ms 14404 KB Output is correct
35 Correct 152 ms 14316 KB Output is correct
36 Correct 139 ms 14404 KB Output is correct
37 Correct 162 ms 14592 KB Output is correct
38 Correct 155 ms 14612 KB Output is correct
39 Correct 243 ms 15472 KB Output is correct
40 Correct 240 ms 15584 KB Output is correct
41 Correct 239 ms 15512 KB Output is correct
42 Correct 260 ms 14600 KB Output is correct