Submission #752999

# Submission time Handle Problem Language Result Execution time Memory
752999 2023-06-04T12:11:19 Z MohamedFaresNebili Cyberland (APIO23_cyberland) C++17
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
 
        using namespace std;
        using ll = long long;
        using pi = pair<double, pair<int, int>>;
 
        const ll M = 1000000000000000005;
        const double epsilon = 0.000001;
 
        double solve(int n, int m, int k, int h, vector<int> x,
                     vector<int> y, vector<int> c, vector<int> arr) {
            double d[n]; d[0] = 0;
            for(int l = 1; l < n; l++) d[l] = M;
            vector<pair<int, int>> adj[n];
            for(int l = 0; l < m; l++) {
                adj[x[l]].push_back({y[l], c[l]});
                adj[y[l]].push_back({x[l], c[l]});
            }
            priority_queue<pi, vector<pi>, greater<pi>> pq;
            pq.push({0, {k + 1, 0}});
            while(!pq.empty()) {
                double w = pq.top().first;
                int u = pq.top().second.second;
                int t = pq.top().second.first; pq.pop();
                for(auto v : adj[u]) {
                    double D = w + v.second;
                    if(arr[v.first] == 0) D = 0;
                    if(arr[v].first != 2) {
                      if(d[v.first] > D) {
                          d[v.first] = D;
                          if(v.first != h) pq.push({d[v.first], {t, v.first}});
                      }
                    }
                    else {
                      if(t > 0) D /= 2.0, t--;
                      else continue;
                      if(d[v.first] > D) {
                          d[v.first] = D;
                          if(v.first != h) pq.push({d[v.first], {t, v.first}});
                      }
                    }
                }
            }
            if(d[h] == M) return -1;
            return d[h];
            return 0;
        }

Compilation message

cyberland.cpp: In function 'double solve(int, int, int, int, std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
cyberland.cpp:28:27: error: no match for 'operator[]' (operand types are 'std::vector<int>' and 'std::pair<int, int>')
   28 |                     if(arr[v].first != 2) {
      |                           ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from cyberland.cpp:1:
/usr/include/c++/10/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++/10/bits/stl_vector.h:1043:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1043 |       operator[](size_type __n) _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~
/usr/include/c++/10/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++/10/bits/stl_vector.h:1061:28: note:   no known conversion for argument 1 from 'std::pair<int, int>' to 'std::vector<int>::size_type' {aka 'long unsigned int'}
 1061 |       operator[](size_type __n) const _GLIBCXX_NOEXCEPT
      |                  ~~~~~~~~~~^~~