結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
srup٩(๑`н´๑)۶
|
| 提出日時 | 2016-06-21 17:50:14 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
OLE
|
| 実行時間 | - |
| コード長 | 1,739 bytes |
| コンパイル時間 | 643 ms |
| コンパイル使用メモリ | 78,224 KB |
| 実行使用メモリ | 3,584 KB |
| 最終ジャッジ日時 | 2024-10-11 18:27:35 |
| 合計ジャッジ時間 | 13,469 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | OLE * 1 -- * 3 |
| other | -- * 26 |
ソースコード
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<pint> vpint;
#define mp make_pairt
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
int dist[210][210];
const int INF = 1e9;
int nex[210] = {-1}; //最短路の直前の頂点
//ワーシャルフロイド法 全点対間最短経路をもとめるとき) (0オリジン)
//dpを利用している
//dist[i][i] = 0 dist[i][j](経路がないもの)= dist[j][i] = INF(1e9)で初期化しておくこと
//dist[i][j] = dist[j][i] = (距離)を代入しておくこと
//この関数を利用することで、dist[i][j]の値(i,j間の距離)の最小値に更新されていく
void floyd(int n){//nは頂点の数
rep(k, n){
rep(i, n){
rep(j, n){
dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
//経路を記録していく
if(dist[i][j] > dist[i][k] + dist[k][j] && nex[i] == -1) nex[i] = k;
}
}
}
}
int main(void){
int n, m, s, g;
cin >> n >> m >> s >> g;
//大きめの数字で初期化
rep(i, 210)rep(j, 210) dist[i][j] = dist[j][i] = INF;
//同じバス停は0
rep(i, 210) dist[i][i] = 0;
//入力
rep(i, m){
int a, b, c;
scanf("%d%d%d", &a,&b,&c);
a--; b--; //0オリジンへ
dist[a][b] = dist[b][a] = c;//バスは往復可能なので、2つに代入すること
}
floyd(n);
printf("%d", s);
int i = s;
while(g != nex[i]){
printf("%d", nex[i]);
i = nex[i];
}
return 0;
}
srup٩(๑`н´๑)۶