結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | naimonon77 |
提出日時 | 2016-02-17 18:14:16 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 2,318 bytes |
コンパイル時間 | 1,551 ms |
コンパイル使用メモリ | 173,760 KB |
実行使用メモリ | 814,848 KB |
最終ジャッジ日時 | 2023-10-22 06:15:11 |
合計ジャッジ時間 | 4,622 ms |
ジャッジサーバーID (参考情報) |
judge10 / judge14 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | WA | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | MLE | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
ソースコード
#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; }