結果

問題 No.160 最短経路のうち辞書順最小
ユーザー BantakoBantako
提出日時 2019-01-01 17:50:17
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 398 ms / 5,000 ms
コード長 1,606 bytes
コンパイル時間 1,852 ms
コンパイル使用メモリ 171,648 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2024-04-25 06:33:28
合計ジャッジ時間 10,765 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 2 ms
5,376 KB
testcase_04 AC 296 ms
5,376 KB
testcase_05 AC 300 ms
5,376 KB
testcase_06 AC 302 ms
5,504 KB
testcase_07 AC 284 ms
6,272 KB
testcase_08 AC 291 ms
6,144 KB
testcase_09 AC 238 ms
6,272 KB
testcase_10 AC 311 ms
6,144 KB
testcase_11 AC 398 ms
6,016 KB
testcase_12 AC 373 ms
6,400 KB
testcase_13 AC 256 ms
6,144 KB
testcase_14 AC 236 ms
6,528 KB
testcase_15 AC 336 ms
6,528 KB
testcase_16 AC 336 ms
6,912 KB
testcase_17 AC 349 ms
6,400 KB
testcase_18 AC 295 ms
6,016 KB
testcase_19 AC 324 ms
6,144 KB
testcase_20 AC 353 ms
6,144 KB
testcase_21 AC 287 ms
6,016 KB
testcase_22 AC 322 ms
6,144 KB
testcase_23 AC 267 ms
5,888 KB
testcase_24 AC 356 ms
6,528 KB
testcase_25 AC 367 ms
6,528 KB
testcase_26 AC 287 ms
6,656 KB
testcase_27 AC 278 ms
7,168 KB
testcase_28 AC 309 ms
7,680 KB
testcase_29 AC 187 ms
8,448 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.cpp:28:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   28 | main(){
      | ^~~~
main.cpp: In function 'int main()':
main.cpp:33:30: warning: narrowing conversion of 'i' from 'int' to 'char' [-Wnarrowing]
   33 |         dist[i][j] = P(INF, {i, j});
      |                              ^
main.cpp:33:30: warning: narrowing conversion of 'i' from 'int' to 'char' [-Wnarrowing]
main.cpp:33:33: warning: narrowing conversion of 'j' from 'int' to 'char' [-Wnarrowing]
   33 |         dist[i][j] = P(INF, {i, j});
      |                                 ^
main.cpp:33:33: warning: narrowing conversion of 'j' from 'int' to 'char' [-Wnarrowing]

ソースコード

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;
typedef pair<int,string> P;
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;
    P dist[N][N];
    rep(i,0,N)rep(j,0,N){
        dest[i][j] = INF;
        dist[i][j] = P(INF, {i, j});
    }
    //rep(i,0,N)dist[i][i].first = 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]].first = dist[B[i]][A[i]].first = C[i];
    }
    
    rep(i,0,N)rep(j,0,N)rep(k,0,N){
        string str = dist[j][i].second + dist[i][k].second.substr(1);
        //string str = dist[j][i].second + dist[i][k].second;
        if(dist[j][k].first > dist[j][i].first + dist[i][k].first ||
        dist[j][k].first == dist[j][i].first + dist[i][k].first &&
        dist[j][k].second > str){
            dist[j][k].first = dist[j][i].first + dist[i][k].first;
            dist[j][k].second = str;
        }
    }
    //cout << dist[S][G].second << endl;
    for(auto c:dist[S][G].second){
        cout << (((int)c) + 256 )% 256 << " ";
    }
    cout << endl;
}
0