結果
問題 | No.160 最短経路のうち辞書順最小 |
ユーザー | なお |
提出日時 | 2015-03-01 23:44:14 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,157 bytes |
コンパイル時間 | 1,405 ms |
コンパイル使用メモリ | 157,160 KB |
実行使用メモリ | 4,504 KB |
最終ジャッジ日時 | 2023-09-06 06:02:01 |
合計ジャッジ時間 | 2,632 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 1 ms
4,376 KB |
testcase_01 | AC | 2 ms
4,380 KB |
testcase_02 | AC | 2 ms
4,376 KB |
testcase_03 | AC | 2 ms
4,380 KB |
testcase_04 | AC | 3 ms
4,376 KB |
testcase_05 | AC | 4 ms
4,376 KB |
testcase_06 | AC | 5 ms
4,376 KB |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | AC | 2 ms
4,376 KB |
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 | AC | 2 ms
4,376 KB |
testcase_20 | AC | 2 ms
4,376 KB |
testcase_21 | WA | - |
testcase_22 | WA | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | AC | 2 ms
4,380 KB |
testcase_28 | WA | - |
testcase_29 | AC | 2 ms
4,376 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector<int> VI; typedef vector<VI> VVI; #define ITER(c) __typeof__((c).begin()) #define FOREACH(it, c) for (ITER(c) it=(c).begin(); it != (c).end(); ++it) #define REP(i, n) for(int(i)=0;(i)<(n);++(i)) #define FOR(i, f, t) for(int(i)=(f);(i)<(t);(++i)) #define RREP(i, n) for(int(i)=(n)-1;(i)>=0;--(i)) #define mp make_pair #define pb push_back const int MOD = int(1e9+7); int N,M,S,G; int res = 0; int g[222][222]; template <class _Tc> class Dijkstra { public: static const int inf = 1<<29; int m_num; vector<vector<pair<int,_Tc> > > m; void init(int n){ m_num = n; m.clear(); m.resize(n); } void add(int u, int v, _Tc e){ m[u].pb(mp(v,e)); } _Tc solve(int u, int v, vector<_Tc> *pcost = NULL, vector<int> *proute = NULL){ int n = m_num; vector<_Tc> c(n, inf); vector<int> r(n, -1); priority_queue<pair<_Tc,int> > q; c[u] = 0; q.push(mp(0, u)); while(!q.empty()){ int u = q.top().second; q.pop(); FOREACH(it,m[u]){ int v = it->first; _Tc nc = c[u] + it->second; if(c[v] > nc || (c[v] == nc && (r[v] == -1 || r[v] > u))){ c[v] = nc; r[v] = u; q.push(mp(-nc,v)); } } } if(pcost) *pcost = c; if(proute) *proute = r; return c[v]; } }; int main(){ do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0); cin >> N >> M >> S >> G; Dijkstra<int> d; d.init(N); REP(i,M){ int a,b,c; cin >> a >> b >> c; d.add(a,b,c); d.add(b,a,c); } VI route; d.solve(S, G, NULL, &route); VI rt; int i = G; while(i != S){ rt.pb(i); i = route[i]; } reverse(rt.begin(), rt.end()); int n = rt.size(); cout << S; REP(i,n) cout << " " << rt[i]; cout << endl; return 0; }