結果

問題 No.788 トラックの移動
ユーザー ミドリムシミドリムシ
提出日時 2019-02-08 22:41:57
言語 C++11
(gcc 11.4.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 2,453 bytes
コンパイル時間 411 ms
コンパイル使用メモリ 65,696 KB
最終ジャッジ日時 2024-04-27 02:48:44
合計ジャッジ時間 710 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: In function ‘std::vector<_Tp> dijkstra(WeightedGraph<T>&, int)’:
main.cpp:37:22: error: ‘numeric_limits’ was not declared in this scope
   37 |     const auto INF = numeric_limits< T >::max();
      |                      ^~~~~~~~~~~~~~
main.cpp:37:40: error: expected primary-expression before ‘>’ token
   37 |     const auto INF = numeric_limits< T >::max();
      |                                        ^
main.cpp:37:46: error: no matching function for call to ‘max()’
   37 |     const auto INF = numeric_limits< T >::max();
      |                                         ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:254:5: note: candidate: ‘template<class _Tp> const _Tp& std::max(const _Tp&, const _Tp&)’
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:254:5: note:   template argument deduction/substitution failed:
main.cpp:37:46: note:   candidate expects 2 arguments, 0 provided
   37 |     const auto INF = numeric_limits< T >::max();
      |                                         ~~~~~^~
In file included from /usr/include/c++/11/bits/char_traits.h:39,
                 from /usr/include/c++/11/ios:40,
                 from /usr/include/c++/11/ostream:38,
                 from /usr/include/c++/11/iostream:39,
                 from main.cpp:1:
/usr/include/c++/11/bits/stl_algobase.h:300:5: note: candidate: ‘template<class _Tp, class _Compare> const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/11/bits/stl_algobase.h:300:5: note:   template argument deduction/substitution failed:
main.cpp:37:46: note:   candidate expects 3 

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;
#define all(x) (x).begin(), (x).end()

template< typename T >
struct edge {
    int src, to;
    T cost;
    
    edge(int to, T cost) : src(-1), to(to), cost(cost) {}
    
    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}
    
    edge &operator=(const int &x) {
        to = x;
        return *this;
    }
    
    operator int() const { return to; }
};

template< typename T >
using Edges = vector< edge< T > >;
template< typename T >
using WeightedGraph = vector< Edges< T > >;
using UnWeightedGraph = vector< vector< int > >;
template< typename T >
using Matrix = vector< vector< T > >;

template< typename T >
vector< T > dijkstra(WeightedGraph< T > &g, int s)
{
    const auto INF = numeric_limits< T >::max();
    vector< T > dist(g.size(), INF);
    
    using Pi = pair< T, int >;
    priority_queue< Pi, vector< Pi >, greater< Pi > > que;
    dist[s] = 0;
    que.emplace(dist[s], s);
    while(!que.empty()) {
        T cost;
        int idx;
        tie(cost, idx) = que.top();
        que.pop();
        if(dist[idx] < cost) continue;
        for(auto &e : g[idx]) {
            auto next_cost = cost + e.cost;
            if(dist[e.to] <= next_cost) continue;
            dist[e.to] = next_cost;
            que.emplace(dist[e.to], e.to);
        }
    }
    return dist;
}

int main(){
    int N, M, L;
    cin >> N >> M >> L;
    int sum = 0;
    int t[N];
    for(int i = 0; i < N; i++){
        cin >> t[i];
        sum += t[i];
    }
    WeightedGraph<long> graph(N);
    for(int i = 0; i < M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        graph[a - 1].push_back(edge<long>(b - 1, c));
        graph[b - 1].push_back(edge<long>(a - 1, c));
    }
    vector<long> dist[N];
    for(int i = 0; i < N; i++){
        dist[i] = dijkstra(graph, i);
    }
    long ans = 1e18;
    for(int i = 0; i < N; i++){
        if(sum == t[i]){
            cout << 0 << endl;
            return 0;
        }
        long cost = 0;
        for(int j = 0; j < N; j++){
            cost += dist[i][j] * t[j] * 2;
        }
        long this_ans = 1e18;
        for(int j = 0; j < N; j++){
            if(!t[j]){
                continue;
            }
            this_ans = min(this_ans, dist[L - 1][j] - dist[i][j]);
        }
        ans = min(ans, cost + this_ans);
    }
    cout << ans << endl;
}
0