結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
kyuna
|
| 提出日時 | 2019-07-28 02:57:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
CE
(最新)
AC
(最初)
|
| 実行時間 | - |
| コード長 | 1,670 bytes |
| コンパイル時間 | 523 ms |
| コンパイル使用メモリ | 69,408 KB |
| 最終ジャッジ日時 | 2024-11-14 21:31:06 |
| 合計ジャッジ時間 | 931 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
コンパイルエラー時のメッセージ・ソースコードは、提出者また管理者しか表示できないようにしております。(リジャッジ後のコンパイルエラーは公開されます)
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
ただし、clay言語の場合は開発者のデバッグのため、公開されます。
コンパイルメッセージ
main.cpp: In function 'Matrix<T> warshall_floyd(Matrix<T>&)':
main.cpp:20:19: error: 'numeric_limits' was not declared in this scope
20 | const T INF = numeric_limits<T>::max();
| ^~~~~~~~~~~~~~
main.cpp:20:35: error: expected primary-expression before '>' token
20 | const T INF = numeric_limits<T>::max();
| ^
main.cpp:20:41: error: no matching function for call to 'max()'
20 | const T INF = numeric_limits<T>::max();
| ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/algorithm:60,
from main.cpp:1:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
254 | max(const _Tp& __a, const _Tp& __b)
| ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:254:5: note: template argument deduction/substitution failed:
main.cpp:20:41: note: candidate expects 2 arguments, 0 provided
20 | const T INF = numeric_limits<T>::max();
| ~~~~~^~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note: candidate: '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)
| ^~~
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/bits/stl_algobase.h:300:5: note: template argument deduction/substitution failed:
main.cpp:20:41: note: candidate expects 3 arguments, 0 provided
20 | const T INF = numeric_limits<T>::max();
| ~~~~~^~
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc@12/12.3.0/include/c++/12/algorithm:61:
/home/linuxbrew/.linuxbrew/Cellar/gcc@12/1
ソースコード
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
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>
Matrix<T> warshall_floyd(Matrix<T> &g) {
Matrix<T> d(g);
const T INF = numeric_limits<T>::max();
for (int k = 0; k < d.size(); k++) {
for (int i = 0; i < d.size(); i++) if (d[i][k] != INF) {
for (int j = 0; j < d.size(); j++) if (d[k][j] != INF) {
d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
}
}
}
return d;
}
template<typename T>
vector<int> build_path(Matrix<T> &mat, Matrix<T> &dist, int s, int t) {
vector<int> path{s};
while (s != t) {
for (int k = 0; k < mat.size(); k++) if (s != k) {
if (mat[s][k] + dist[k][t] == dist[s][t]) {
path.emplace_back(k); s = k; break;
}
}
}
return path;
}
int main() {
const int INF = numeric_limits<int>::max();
int N, M, S, G; cin >> N >> M >> S >> G;
Matrix<int> mat(N, vector<int>(N, INF));
for (int i = 0; i < N; i++) mat[i][i] = 0;
while (M--) {
int a, b, c; cin >> a >> b >> c;
mat[a][b] = mat[b][a] = c;
}
Matrix<int> dist = warshall_floyd(mat);
for (int v: build_path(mat, dist, S, G)) cout << v << " \n"[v == G];
return 0;
}
kyuna