답안 #876791

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876791 2023-11-22T10:41:27 Z dimashhh 사이버랜드 (APIO23_cyberland) C++17
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 1e5;

double d[N][70],used[N][20];

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)
{
    vector<vector<pair<int,double>> g(n);   
    if(k >= 66){
        k = 66;
    }
    for (int i = 0; i < n; i++)
    {
        for(int j = 0;j <= k;j++){
            d[i][j] = 1e15;
            used[i][j] = 0;
        }
    }
    for (int i = 0; i < m; i++)
    {
        g[x[i]].epmlace_back({y[i], c[i]});
        g[y[i]].emplace_back({x[i], c[i]});
    }
    queue<int> q;
    vector<int> can(n,0);
    can[0] = 1;
    q.push(0);
    priority_queue<pair<double,pair<int,int>>> st;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        if(!can[v]) continue;
        if((arr[v] == 0 || v == 0) && can[v]){
            d[v][0] = 0;
            st.push({0,{0,v}});
        }
        for(auto [to,w]:g[v]){
            if(to == h || can[to]) continue;
            q.push(to);
            can[to] = 1;
        }
    }
    
    st.push({0,{0,0}});
    double res = 1e15;
    while(!st.empty()){
        double x = (st.top()).first;
        auto [col,v] = (st.top()).second;
        st.pop();
        if(used[v][col]) continue;
        used[v][col] = 1;
        if(v == h){
            res = min(res,d[v][col]);
            continue;
        }
        for(auto [to,w]:g[v]){
            if(to == h || !can[to]) continue;
            if(d[to][col + 1] != -1 && col + 1 <= k && arr[to] == 2 && d[to][col + 1] > (d[v][col] + w) / 2){
                d[to][col + 1] = (d[v][col] + w) / 2;
                st.push({-d[to][col + 1],{col + 1,to}});
            }
            if(d[to][col] != -1 && d[to][col] > d[v][col] + w){
                d[to][col] = d[v][col] + w;
                st.push({-d[to][col],{col,to}});
            }
        }
        d[v][col] = -1;
    }
    if(res == 1e15) res = -1;
    return res;
}
// int main() {
//   int T;
//   assert(1 == scanf("%d", &T));
//   while (T--){
//     int N,M,K,H;
//     assert(4 == scanf("%d %d %d\n%d", &N, &M, &K, &H));
//     std::vector<int> x(M);
//     std::vector<int> y(M);
//     std::vector<int> c(M);
//     std::vector<int> arr(N);
//     for (int i=0;i<N;i++)
//       assert(1 == scanf("%d", &arr[i]));
//     for (int i=0;i<M;i++)
//       assert(3 == scanf("%d %d %d", &x[i], &y[i], &c[i]));
//     printf("%.12lf\n", solve(N, M, K, H, x, y, c, arr));
//   }
// }

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:11:40: error: template argument 1 is invalid
   11 |     vector<vector<pair<int,double>> g(n);
      |                                        ^
cyberland.cpp:11:40: error: template argument 2 is invalid
cyberland.cpp:24:9: error: 'g' was not declared in this scope
   24 |         g[x[i]].epmlace_back({y[i], c[i]});
      |         ^
cyberland.cpp:40:25: error: 'g' was not declared in this scope
   40 |         for(auto [to,w]:g[v]){
      |                         ^
cyberland.cpp:59:25: error: 'g' was not declared in this scope
   59 |         for(auto [to,w]:g[v]){
      |                         ^
cyberland.cpp:63:55: error: no matching function for call to 'std::priority_queue<std::pair<double, std::pair<int, int> > >::push(<brace-enclosed initializer list>)'
   63 |                 st.push({-d[to][col + 1],{col + 1,to}});
      |                                                       ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from cyberland.cpp:1:
/usr/include/c++/10/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> >, std::allocator<std::pair<double, std::pair<int, int> > > >; _Compare = std::less<std::pair<double, std::pair<int, int> > >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<double, std::pair<int, int> >]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<double, std::pair<int, int> >&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> >, std::allocator<std::pair<double, std::pair<int, int> > > >; _Compare = std::less<std::pair<double, std::pair<int, int> > >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<double, std::pair<int, int> >]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<double, std::pair<int, int> > >::value_type&&' {aka 'std::pair<double, std::pair<int, int> >&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
cyberland.cpp:67:47: error: no matching function for call to 'std::priority_queue<std::pair<double, std::pair<int, int> > >::push(<brace-enclosed initializer list>)'
   67 |                 st.push({-d[to][col],{col,to}});
      |                                               ^
In file included from /usr/include/c++/10/queue:64,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:86,
                 from cyberland.cpp:1:
/usr/include/c++/10/bits/stl_queue.h:640:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> >, std::allocator<std::pair<double, std::pair<int, int> > > >; _Compare = std::less<std::pair<double, std::pair<int, int> > >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<double, std::pair<int, int> >]'
  640 |       push(const value_type& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:640:30: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type&' {aka 'const std::pair<double, std::pair<int, int> >&'}
  640 |       push(const value_type& __x)
      |            ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_queue.h:648:7: note: candidate: 'void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<double, std::pair<int, int> >; _Sequence = std::vector<std::pair<double, std::pair<int, int> >, std::allocator<std::pair<double, std::pair<int, int> > > >; _Compare = std::less<std::pair<double, std::pair<int, int> > >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<double, std::pair<int, int> >]'
  648 |       push(value_type&& __x)
      |       ^~~~
/usr/include/c++/10/bits/stl_queue.h:648:25: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<double, std::pair<int, int> > >::value_type&&' {aka 'std::pair<double, std::pair<int, int> >&&'}
  648 |       push(value_type&& __x)
      |            ~~~~~~~~~~~~~^~~
cyberland.cpp:50:16: warning: unused variable 'x' [-Wunused-variable]
   50 |         double x = (st.top()).first;
      |                ^