結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
古寺いろは
|
| 提出日時 | 2015-03-25 19:40:41 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 990 bytes |
| コンパイル時間 | 1,624 ms |
| コンパイル使用メモリ | 175,100 KB |
| 実行使用メモリ | 814,264 KB |
| 最終ジャッジ日時 | 2024-06-29 00:57:07 |
| 合計ジャッジ時間 | 8,772 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 WA * 1 |
| other | AC * 3 MLE * 1 -- * 22 |
ソースコード
#include "bits/stdc++.h"
using namespace std;
int main() {
int N, M, S, G;
cin >> N >> M >> S >> G;
vector<vector<pair<int, int>>> es(N);
for (int i = 0; i < M; i++)
{
int a, b, c;
cin >> a >> b >> c;
es[a].push_back(make_pair(b, c - 1));
es[b].push_back(make_pair(a, c - 1));
}
int MAX = 99999999;
vector<pair<int, int>> dp(N);
for (int i = 0; i < N; i++)
{
dp[i] = make_pair(MAX, -1);
sort(es[i].begin(), es[i].end());
}
dp[G] = make_pair(0, -1);
priority_queue<pair<pair<int, int>,int>> pq;
pq.push(make_pair(make_pair(0, -1), G));
while (!pq.empty()){
auto now = pq.top(); pq.pop();
int p = now.second;
if (dp[p] < now.first) continue;
for (auto to : es[p]){
int p2 = to.first;
auto next = make_pair(to.second + dp[p].first, p);
if (dp[p2] > next){
dp[p2] = next;
pq.push(make_pair(next, p2));
}
}
}
string ans = to_string(S);
while (S != G){
S = dp[S].second;
ans += " " + to_string(S);
}
cout << ans << endl;
}
古寺いろは