結果

問題 No.160 最短経路のうち辞書順最小
ユーザー tsutajtsutaj
提出日時 2017-07-04 19:31:57
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 1,750 bytes
コンパイル時間 1,755 ms
コンパイル使用メモリ 173,728 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-15 16:10:16
合計ジャッジ時間 2,708 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 3 ms
5,376 KB
testcase_04 AC 6 ms
5,376 KB
testcase_05 AC 9 ms
5,376 KB
testcase_06 AC 11 ms
5,376 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 4 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 AC 3 ms
5,376 KB
testcase_20 AC 4 ms
5,376 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 AC 2 ms
5,376 KB
testcase_28 WA -
testcase_29 AC 3 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

// 基本テンプレート (縮小版)

#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define int long long
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
typedef pair<int, int> pii;
typedef long long ll;
constexpr ll INF = 1001001001001001LL;
constexpr ll MOD = 1000000007LL;

int N, M, S, G;
int dist[210];
int E[210][210];

signed main() {
    memset(E, -1, sizeof(E));
    cin >> N >> M >> S >> G;
    rep(i,0,M) {
        int a, b, c; cin >> a >> b >> c;
        E[a][b] = c;
        E[b][a] = c;
    }
    fill(dist, dist+N, INF);
    dist[S] = 0;

    priority_queue< pii, vector<pii>, greater<pii> > q;
    q.push( pii(0, S) );
    while(!q.empty()) {
        pii cur = q.top(); q.pop();
        int d = cur.first, pt = cur.second;
        repr(i,N-1,0) {
            if(i == pt || E[i][pt] < 0) continue;
            if(dist[i] > dist[pt] + E[i][pt]) {
                dist[i] = dist[pt] + E[i][pt];
                q.push( pii(dist[i], i) );
            }
        }
    }

    vector<int> ans;
    int d = dist[G], pt = G;
    ans.push_back(pt);
    while(d != 0) {
        rep(i,0,N) {
            if(i == pt || E[i][pt] < 0) continue;
            if(d - dist[i] == E[i][pt]) {
                pt = i;
                d = dist[i];
                ans.push_back(i);
                break;
            }
        }
    }
    reverse(ans.begin(), ans.end());
    rep(i,0,ans.size()) cout << (i==0 ? "" : " ") << ans[i];
    cout << endl;
    return 0;
}
0