답안 #124544

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
124544 2019-07-03T13:40:29 Z AdOjis485 관광 (NOI14_sightseeing) C++14
컴파일 오류
0 ms 0 KB
//
//  main.cpp
//  sightseeing
//
//  Created by AdOjis485 on 03.07.19.
//  Copyright © 2019 AdOjis485. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#define int int64_t
using namespace std;
/*
bool bfs(int x, int m, vector<vector<pair<int, int>>> adi){
    queue<int> q;
    q.push(0);
    vector<bool> vis(adi.size(), false);
    while(q.size() > 0){
        int cur = q.front();
        q.pop();
        if(!vis[cur]){
            vis[cur] = true;
            for(pair<int, int> next : adi[cur]){
                if(!vis[next.first] && next.second >= m){
                    q.push(next.first);
                }
            }
        }
    }
    return vis[x];
}
*/

vector<int> dijkstra(vector<vector<pair<int, int>>>& adi){
    priority_queue<pair<int, int>> pq;
    pq.push({numeric_limits<int>::max(), 0});
    vector<int> vis(adi.size(), -1);
    while(pq.size() > 0){
        int cur = pq.top().second;
        int cq = pq.top().first;
        pq.pop();
        if(vis[cur] == -1 || vis[cur] < cq){
            vis[cur] = cq;
            for(pair<int, int> next : adi[cur]){
                if(vis[next.first] < cq){
                    pq.push({min(cq, next.second), next.first});
                }
            }
        }
    }
    return vis;
}

signed main() {
    int v, e, q;
    cin >> v >> e >> q;
    vector<vector<pair<int, int>>> adi(v);
    int maxq = 0;
    for(int i = 0; i < e; i ++){
        int v1, v2, qu;
        cin >> v1 >> v2 >> qu;
        v1 --;
        v2 --;
        adi[v1].push_back({v2, qu});
        adi[v2].push_back({v1, qu});
        maxq = max(maxq, qu);
    }
    vector<int> vis = dijkstra(adi);
    for(int i = 0; i < q; i ++){
        int x;
        cin >> x;
        x --;
        /*
        int mi = 0;
        int ma = maxq + 1;
        while(mi < ma - 1){
            int m = (mi + ma) / 2;
            if(bfs(x, m, adi)){
                mi = m;
            }
            else{
                ma = m;
            }
        }
        cout << mi << '\n';
         */
        cout << vis[x] << '\n';
    }
    return 0;
}

Compilation message

sightseeing.cpp: In function 'std::vector<long int> dijkstra(std::vector<std::vector<std::pair<long int, long int> > >&)':
sightseeing.cpp:37:14: error: 'numeric_limits' was not declared in this scope
     pq.push({numeric_limits<int>::max(), 0});
              ^~~~~~~~~~~~~~
sightseeing.cpp:37:32: error: expected primary-expression before '>' token
     pq.push({numeric_limits<int>::max(), 0});
                                ^
sightseeing.cpp:37:39: error: no matching function for call to 'max()'
     pq.push({numeric_limits<int>::max(), 0});
                                       ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from sightseeing.cpp:9:
/usr/include/c++/7/bits/stl_algobase.h:219:5: note: candidate: template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)
     max(const _Tp& __a, const _Tp& __b)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:219:5: note:   template argument deduction/substitution failed:
sightseeing.cpp:37:39: note:   candidate expects 2 arguments, 0 provided
     pq.push({numeric_limits<int>::max(), 0});
                                       ^
In file included from /usr/include/c++/7/bits/char_traits.h:39:0,
                 from /usr/include/c++/7/ios:40,
                 from /usr/include/c++/7/ostream:38,
                 from /usr/include/c++/7/iostream:39,
                 from sightseeing.cpp:9:
/usr/include/c++/7/bits/stl_algobase.h:265:5: note: candidate: template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)
     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
     ^~~
/usr/include/c++/7/bits/stl_algobase.h:265:5: note:   template argument deduction/substitution failed:
sightseeing.cpp:37:39: note:   candidate expects 3 arguments, 0 provided
     pq.push({numeric_limits<int>::max(), 0});
                                       ^
sightseeing.cpp:37:44: error: no matching function for call to 'std::priority_queue<std::pair<long int, long int> >::push(<brace-enclosed initializer list>)'
     pq.push({numeric_limits<int>::max(), 0});
                                            ^
In file included from /usr/include/c++/7/queue:64:0,
                 from sightseeing.cpp:11:
/usr/include/c++/7/bits/stl_queue.h:595:7: note: candidate: void std::priority_queue<_Tp, _Sequence, _Compare>::push(const value_type&) [with _Tp = std::pair<long int, long int>; _Sequence = std::vector<std::pair<long int, long int> >; _Compare = std::less<std::pair<long int, long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long int, long int>]
       push(const value_type& __x)
       ^~~~
/usr/include/c++/7/bits/stl_queue.h:595:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'const value_type& {aka const std::pair<long int, long int>&}'
/usr/include/c++/7/bits/stl_queue.h:603:7: note: candidate: void std::priority_queue<_Tp, _Sequence, _Compare>::push(std::priority_queue<_Tp, _Sequence, _Compare>::value_type&&) [with _Tp = std::pair<long int, long int>; _Sequence = std::vector<std::pair<long int, long int> >; _Compare = std::less<std::pair<long int, long int> >; std::priority_queue<_Tp, _Sequence, _Compare>::value_type = std::pair<long int, long int>]
       push(value_type&& __x)
       ^~~~
/usr/include/c++/7/bits/stl_queue.h:603:7: note:   no known conversion for argument 1 from '<brace-enclosed initializer list>' to 'std::priority_queue<std::pair<long int, long int> >::value_type&& {aka std::pair<long int, long int>&&}'