結果

問題 No.17 2つの地点に泊まりたい
ユーザー kyunakyuna
提出日時 2019-08-19 13:51:32
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
CE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,559 bytes
コンパイル時間 431 ms
コンパイル使用メモリ 62,388 KB
最終ジャッジ日時 2023-07-27 11:41:34
合計ジャッジ時間 811 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。

コンパイルメッセージ
main.cpp: 関数 ‘void warshall_floyd(Matrix<T>&)’ 内:
main.cpp:17:19: エラー: ‘numeric_limits’ was not declared in this scope
   17 |     const T INF = numeric_limits<T>::max();
      |                   ^~~~~~~~~~~~~~
main.cpp:17:35: エラー: expected primary-expression before ‘>’ token
   17 |     const T INF = numeric_limits<T>::max();
      |                                   ^
main.cpp:17:41: エラー: ‘max()’ の呼び出しに適合する関数がありません
   17 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/algorithm:60,
         次から読み込み:  main.cpp:1:
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:254:5: 備考: 候補: ‘template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)’
  254 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:254:5: 備考:   template argument deduction/substitution failed:
main.cpp:17:41: 備考:   候補では 2 個の引数が予期されますが、0 個の引数が与えられています
   17 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:300:5: 備考: 候補: ‘template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)’
  300 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/local/gcc7/include/c++/12.2.0/bits/stl_algobase.h:300:5: 備考:   template argument deduction/substitution failed:
main.cpp:17:41: 備考:   候補では 3 個の引数が予期されますが、0 個の引数が与えられています
   17 |     const T INF = numeric_limits<T>::max();
      |                                    ~~~~~^~
次のファイルから読み込み:  /usr/local/gcc7/include/c++/12.2.0/algorithm:61:

ソースコード

diff #

#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

template <typename T>
struct Edge { int src, dst; T cost;
    Edge(int dst, T cost) : src(-1), dst(dst), cost(cost) { }
    Edge(int src, int dst, T cost) : src(src), dst(dst), cost(cost) { }
};
template <typename T> using Edges = vector<Edge<T>>;
template <typename T> using WeightedGraph = vector<Edges<T>>;
template <typename T> using Matrix = vector<vector<T>>;

template <typename T>
void warshall_floyd(Matrix<T> &g) {
    const T INF = numeric_limits<T>::max();
    for (int k = 0; k < g.size(); k++) {
        for (int i = 0; i < g.size(); i++) if (g[i][k] != INF) {
            for (int j = 0; j < g.size(); j++) if (g[k][j] != INF) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}

int main() {
    int n; cin >> n;
    vector<int> s(n);
    for (int &si: s) cin >> si;
    const auto INF = numeric_limits<int>::max();
    Matrix<int> dist(n, vector<int>(n, INF));
    int m; cin >> m;
    for (int i = 0; i < n; i++) dist[i][i] = 0;
    while (m--) {
        int a, b, c; cin >> a >> b >> c;
        dist[a][b] = dist[b][a] = c;
    }
    warshall_floyd(dist);
    int ans = INF;
    for (int i = 1; i < n - 1; i++) {
        if (dist[0][i] == INF) continue;
        for (int j = 1; j < n - 1; j++) if (i != j) {
            if (dist[i][j] == INF || dist[j][n - 1] == INF) continue;
            ans = min(ans, dist[0][i] + s[i] + dist[i][j] + s[j] + dist[j][n - 1]);
        }
    }
    cout << ans << endl;
    return 0;
}
0