結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | Bantako |
提出日時 | 2019-01-01 17:49:30 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 1,604 bytes |
コンパイル時間 | 1,806 ms |
コンパイル使用メモリ | 175,180 KB |
実行使用メモリ | 8,576 KB |
最終ジャッジ日時 | 2024-11-07 16:40:18 |
合計ジャッジ時間 | 11,179 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
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 | WA | - |
testcase_20 | WA | - |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | WA | - |
コンパイルメッセージ
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]
ソースコード
#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; }