結果
| 問題 |
No.160 最短経路のうち辞書順最小
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2016-02-17 18:14:16 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 2,318 bytes |
| コンパイル時間 | 1,606 ms |
| コンパイル使用メモリ | 172,524 KB |
| 実行使用メモリ | 814,712 KB |
| 最終ジャッジ日時 | 2024-09-22 07:30:22 |
| 合計ジャッジ時間 | 4,408 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 4 |
| other | WA * 3 MLE * 1 -- * 22 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#ifdef __unix__
#include <bits/stdc++.h>
#else
#include "bits\stdc++.h"
#endif
#include <vector>
#include <set>
#include <string>
#include <queue>
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
struct Route{
int next,cost,num;
};
struct long_Route{
vector<int> route;
int cost;
};
int N,M,S,G;
vector<Route> st[205];
vector<int> shortest_route;
int min_cost = INT_MAX;
bool isfast(vector<int> v1,vector<int> v2) {
int i;
if(v2.size() == 0) return true;
int min_size = v1.size();
if(min_size > v2.size()) min_size = v2.size();
rep(i,min_size) {
if(v1[i] < v2[i]) return true;
if(v1[i] > v2[i]) return false;
}
return false;
}
void print_v(vector<int> v) {
int i;
rep(i,v.size()-1 ) {
printf("%d ",v[i]);
}
printf("%d\n",v[i]);
}
void bfs() {
int test = 1;
if(test) puts("");
int i;
queue<long_Route> qu;
long_Route start;
start.route.push_back(S);
start.cost = 0;
qu.push(start);
while( not qu.empty() ) {
long_Route lR = qu.front(); qu.pop();
vector<Route> now_st
= st[lR.route[lR.route.size()-1]] ;
rep(i,now_st.size()) {
Route now_route1 = now_st[i];
long_Route lR1 = lR;
if(now_route1.next == G
&& lR1.cost + lR.cost <= min_cost
&& isfast(lR1.route,shortest_route) ) {
lR1.route.push_back(now_route1.next);
shortest_route = lR1.route;
min_cost = lR1.cost + lR.cost;
}
if(lR.route.size() == 1) {
lR1.route.push_back(now_route1.next);
lR1.cost = now_route1.cost;
qu.push(lR1);
}
else if(now_route1.cost + lR.cost <= min_cost
&& now_route1.next != lR.route[lR.route.size()-2]) {
lR1.route.push_back(now_route1.next);
lR1.cost = now_route1.cost + lR.cost;
qu.push(lR1);
}
}
}
}
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int i,j,k;
cin >> N >> M >> S >> G;
rep(i,M) {
int a,b,c;
cin >> a >> b >> c;
Route tmp = {b,c,i};
st[a].push_back(tmp);
tmp.next = a; tmp.num = M+i;
st[b].push_back(tmp);
}
bfs();
print_v(shortest_route);
return 0;
}