Submission #1232219

#TimeUsernameProblemLanguageResultExecution timeMemory
1232219dizzy_groovyCyberland (APIO23_cyberland)C++20
Compilation error
0 ms0 KiB
#include "cyberland.h"

#include <bits/stdc++.h>

using namespace std;

const double INF = 1e18;

void dfs(int i, vector<bool> &used, vector<vector<pair<int, double>>> &gr, int h) {
    if (used[i]) return;
    used[i] = true;
    if (i == h) return;
    for (auto &x : gr[i]) dfs(x.first, used, gr, h);
}

double solve(int n, int m, int k, int h, std::vector<int> x, std::vector<int> y, std::vector<int> c, std::vector<int> arr) {
    //k--;
    if (k > 30) k = 30;
    vector<vector<double>> dist(k + 1, vector<double> (n, INF));
    vector<vector<pair<int, double>>> gr(n);
    for (int i = 0; i < m; i++) {
        gr[x[i]].push_back({y[i], c[i]});
        gr[y[i]].push_back({x[i], c[i]});
    }
    gr[h].clear();
    vector<bool> used(n);
    dfs(0, used, gr, h);
    if (!used[h]) return -1;
    vector<int> st(1, 0);
    for (int i = 0; i < n; i++) {
        if (used[i] && arr[i] == 0) st.push_back(i);
    }
    set<pair<double, int>> s;
    for (auto &x : st) {
        s.insert({0, x});
    }
    double ans = INF;
    for (int it = 0; it <= k; it++) {
        while (s.size() > 0) {
            int i = ((s.begin()))->second;
            if (dist[it][i] <= ((s.begin())->first)) {
                s.erase(s.begin());
                continue;
            }
            dist[it][i] = ((s.begin())->first);
            s.erase(s.begin());
            if (i == h) continue;
            for (auto &x : gr[i]) {
                s.insert({dist[it][i] + x.second, x.first});
            }
        }
        ans = min(ans, dist[it][h]);
        if (it < k) {
            for (int i = 0; i < n; i++) {
                if (i == h) continue;
                if (arr[i] == 2) {
                    for (auto &x : gr[i]) {
                        if (arr[x] == 0) continue;
                        s.insert({dist[it][i] / 2 + x.second, x.first});
                    }
                }
            }
        }
    }
    assert(ans != INF);
    return ans;
}
/*
1
7 6 30
6
1 1 2 2 1 1 1
0 1 62830208
1 2 43207456
2 3 365326424
3 4 364309910
4 5 859258884
5 6 933234961
*/

Compilation message (stderr)

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:58:32: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::pair<int, double>')
   58 |                         if (arr[x] == 0) continue;
      |                                ^
In file included from /usr/include/c++/11/vector:67,
                 from cyberland.h:1,
                 from cyberland.cpp:1:
/usr/include/c++/11/bits/stl_vector.h:1043:7: note: candidate: 'std::vector<_Tp, _Alloc>::reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::reference = int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::pair<int, double>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/11/bits/stl_vector.h:1061:7: note: candidate: 'std::vector<_Tp, _Alloc>::const_reference std::vector<_Tp, _Alloc>::operator[](std::vector<_Tp, _Alloc>::size_type) const [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::const_reference = const int&; std::vector<_Tp, _Alloc>::size_type = long unsigned int]'
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |       ^~~~~~~~
/usr/include/c++/11/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::pair<int, double>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~