結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
Bantako
|
| 提出日時 | 2019-01-01 17:50:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 389 ms / 5,000 ms |
| コード長 | 1,606 bytes |
| コンパイル時間 | 1,734 ms |
| コンパイル使用メモリ | 175,328 KB |
| 実行使用メモリ | 8,448 KB |
| 最終ジャッジ日時 | 2024-11-07 16:41:54 |
| 合計ジャッジ時間 | 10,726 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 26 |
コンパイルメッセージ
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;
}
Bantako