|  | 
|  | 1 | +#include <bits/stdc++.h> | 
|  | 2 | +#define INF 9223372036854775807 | 
|  | 3 | + | 
|  | 4 | +using namespace std; | 
|  | 5 | +using ll = long long; | 
|  | 6 | +using pll = pair<ll, ll>; | 
|  | 7 | +using plvl = pair<ll, vector<ll>>; | 
|  | 8 | + | 
|  | 9 | +ll dis[1001], cost[1001][1001]; | 
|  | 10 | +bool vst[1001][1001]; | 
|  | 11 | + | 
|  | 12 | +struct compare | 
|  | 13 | +{ | 
|  | 14 | + bool operator()(const plvl &a, const plvl &b) const | 
|  | 15 | + { | 
|  | 16 | + return a.first > b.first; | 
|  | 17 | + } | 
|  | 18 | +}; | 
|  | 19 | + | 
|  | 20 | +int main() | 
|  | 21 | +{ | 
|  | 22 | + ios_base::sync_with_stdio(0); | 
|  | 23 | + cin.tie(0); | 
|  | 24 | + ll n, m, a, b, c, i, s, e; | 
|  | 25 | + vector<ll> cv, gph[1001]; | 
|  | 26 | + plvl cr, res; | 
|  | 27 | + priority_queue<plvl, vector<plvl>, compare> pq; | 
|  | 28 | + cin >> n >> m; | 
|  | 29 | + while (m--) | 
|  | 30 | + { | 
|  | 31 | + cin >> a >> b >> c; | 
|  | 32 | + if (a == b) | 
|  | 33 | + { | 
|  | 34 | + continue; | 
|  | 35 | + } | 
|  | 36 | + else if (vst[a][b]) | 
|  | 37 | + { | 
|  | 38 | + cost[a][b] = min(cost[a][b], c); | 
|  | 39 | + } | 
|  | 40 | + else | 
|  | 41 | + { | 
|  | 42 | + gph[a].push_back(b); | 
|  | 43 | + vst[a][b] = true; | 
|  | 44 | + cost[a][b] = c; | 
|  | 45 | + } | 
|  | 46 | + } | 
|  | 47 | + cin >> s >> e; | 
|  | 48 | + for (i = 1; i <= n; i++) | 
|  | 49 | + { | 
|  | 50 | + dis[i] = INF; | 
|  | 51 | + } | 
|  | 52 | + cv.push_back(s); | 
|  | 53 | + dis[s] = 0; | 
|  | 54 | + pq.push(make_pair(0, cv)); | 
|  | 55 | + while (pq.empty() == false) | 
|  | 56 | + { | 
|  | 57 | + cr = pq.top(); | 
|  | 58 | + cv = cr.second; | 
|  | 59 | + pq.pop(); | 
|  | 60 | + c = cv.back(); | 
|  | 61 | + if (c == e) | 
|  | 62 | + { | 
|  | 63 | + res = cr; | 
|  | 64 | + break; | 
|  | 65 | + } | 
|  | 66 | + for (auto i : gph[c]) | 
|  | 67 | + { | 
|  | 68 | + if (cost[c][i] + cr.first < dis[i]) | 
|  | 69 | + { | 
|  | 70 | + dis[i] = cost[c][i] + cr.first; | 
|  | 71 | + cv.push_back(i); | 
|  | 72 | + pq.push(make_pair(dis[i], cv)); | 
|  | 73 | + cv.pop_back(); | 
|  | 74 | + } | 
|  | 75 | + } | 
|  | 76 | + } | 
|  | 77 | + cout << res.first << "\n"; | 
|  | 78 | + b = res.second.size(); | 
|  | 79 | + cout << b << "\n"; | 
|  | 80 | + for (i = 0; i < b; i++) | 
|  | 81 | + { | 
|  | 82 | + cout << res.second[i] << " "; | 
|  | 83 | + } | 
|  | 84 | + return 0; | 
|  | 85 | +} | 
0 commit comments