結果

問題 No.160 最短経路のうち辞書順最小
ユーザー BantakoBantako
提出日時 2019-01-01 16:45:55
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
TLE  
実行時間 -
コード長 1,188 bytes
コンパイル時間 1,463 ms
コンパイル使用メモリ 170,132 KB
実行使用メモリ 8,752 KB
最終ジャッジ日時 2023-08-07 08:22:13
合計ジャッジ時間 8,171 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 2 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 11 ms
4,380 KB
testcase_05 AC 13 ms
4,376 KB
testcase_06 AC 15 ms
4,376 KB
testcase_07 TLE -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:27:1: 警告: ISO C++ では型の無い ‘main’ の宣言を禁止しています [-Wreturn-type]
   27 | main(){
      | ^~~~

ソースコード

diff #

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
int N,M,S,G;
int dest[200][200];
int used[200];
stack<int> st;
bool dfs(int now, int res){
    if(now == G && res == 0){
        st.push(now);
        return true;
    }
    rep(i,0,N){
        if(i == now || used[i] || res < dest[now][i])continue;
        used[i] = 1;
        if(dfs(i, res - dest[now][i])){
            st.push(now);
            return true;
        }
        used[i] = 0;
    }
    return false;
}
main(){
    cin >> N >> M >> S >> G;
    int dist[N][N];
    rep(i,0,N)rep(j,0,N)dest[i][j] = dist[i][j] = INF;
    rep(i,0,N)dist[i][i] = 0;
    int A[M],B[M],C[M];
    rep(i,0,M){
        cin >> A[i] >> B[i] >> C[i];
        dest[A[i]][B[i]] = dest[B[i]][A[i]] = C[i];
        dist[A[i]][B[i]] = dist[B[i]][A[i]] = C[i];
    }
    rep(i,0,N)rep(j,0,N)rep(k,0,N){
        dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
    }
    //cout << dist[S][G] << endl;
    used[S] = 1;
    dfs(S, dist[S][G]);
    while(!st.empty()){
        cout << st.top() << " ";
        st.pop();
    }
    cout << endl;
}
0