結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
cormoran
|
| 提出日時 | 2016-06-21 17:53:12 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,268 bytes |
| コンパイル時間 | 862 ms |
| コンパイル使用メモリ | 84,128 KB |
| 実行使用メモリ | 6,824 KB |
| 最終ジャッジ日時 | 2024-10-11 18:28:44 |
| 合計ジャッジ時間 | 1,838 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 8 WA * 18 |
ソースコード
#include<iostream>
#include<vector>
#include<cassert>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<tuple>
#include<numeric>
using namespace std;
using pii = pair<int,int>;
using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()
#define debug(x) cerr << #x << " : " << x << endl
// vector
template<class T> ostream& operator << (ostream &os , const vector<T> &v) {
for(const T &t : v) os << "\t" << t; return os << endl;
}
template<class T> istream& operator >> (istream &is , vector<T> &v) {
for(T &a : v) is >> a; return is;
}
// pair
template<class T, class U> ostream& operator << (ostream &os , const pair<T, U> &v) {
return os << "<" << v.first << " " << v.second << ">";
}
const int INF = 1 << 30;
bool solve() {
int N, M, S, G; cin >> N >> M >> S >> G;
vector<vector<pii>> E(N);
rep(i, M) {
int a, b, c; cin >> a >> b >> c;
E[a].push_back(make_pair(b, c));
E[b].push_back(make_pair(a, c));
}
priority_queue<pii> que;
vector<int> dist(N, INF);
que.push(make_pair(S, 0));
dist[S] = 0;
while(que.size()) {
int now = que.top().first;
int cost = que.top().second; que.pop();
if(dist[now] < cost) continue;
for(pii nxt : E[now]) {
int ncost = cost + nxt.second;
if(dist[nxt.first] > ncost) {
dist[nxt.first] = ncost;
que.push(make_pair(nxt.first, ncost));
}
}
}
vector<int> road;
int now = G;
road.push_back(now);
while(now != S) {
int prev = INF;
for(pii nxt : E[now]) {
if(dist[nxt.first] + nxt.second == dist[now]) {
prev = min(prev, nxt.first);
}
}
now = prev;
road.push_back(now);
}
reverse(all(road));
rep(i, road.size()) {
if(i > 0) cout << " ";
cout << road[i];
}
cout << endl;
return false;
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
while(solve());
return 0;
}
cormoran