Advertisement
Guest User

Untitled

a guest
Dec 8th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.87 KB | None | 0 0
  1. #include <vector>
  2. #include <sstream>
  3. #include <algorithm>
  4. #include <fstream>
  5. #include <list>
  6. #include <bitset>
  7. #include <map>
  8. #include <istream>
  9. #include <stack>
  10. #include <sstream>
  11. #include <unordered_map>
  12. #include <set>
  13. #include <cmath>
  14. #include <iostream>
  15. #include <iomanip>
  16. #include <queue>
  17. #include <string>
  18.  
  19. #define endl "\n"
  20. #define all(x) x.begin(),x.end()
  21. #define xx first
  22. #define yy second
  23. #define rr return 0
  24. #define pii pair<int,int>
  25.  
  26. typedef long long ll;
  27. typedef long double ld;
  28.  
  29. const int NMAX = 5005;
  30. const int MMAX = 100000 + 5;
  31. const int KMAX = 5005;
  32.  
  33. const ll INF = 1e15;
  34.  
  35. using namespace std;
  36.  
  37. int n, m, k;
  38. int a, b;
  39. pair<ll, ll> c[KMAX];
  40. vector<pair<ll, ll>> g[NMAX];
  41. ll d[NMAX][2];
  42.  
  43. void djk(int from, int ind){
  44. for(int i = 1;i <= n;i++){
  45. d[i][ind] = INF;
  46. }
  47. d[from][ind] = 0;
  48. set<pair<ll, ll>> st;
  49. st.insert({d[from][ind], from});
  50. while(!st.empty()){
  51. pair<ll, ll> v = *st.begin();
  52. st.erase(st.begin());
  53. for(int i = 0;i < g[v.yy].size();i++){
  54. ll to = g[v.yy][i].xx;
  55. ll w = g[v.yy][i].yy;
  56. if(d[to][ind] > (d[v.yy][ind] + w)){
  57. st.erase({d[to][ind], to});
  58. d[to][ind] = d[v.yy][ind] + w;
  59. st.insert({d[to][ind], to});
  60. }
  61. }
  62. }
  63. }
  64.  
  65. signed main() {
  66. ios::sync_with_stdio(false);
  67. cin.tie(0);
  68. cout.tie(0);
  69. cin >> n >> m >> k;
  70. cin >> a >> b;
  71. for(int i = 1;i <= k;i++){
  72. cin >> c[i].xx >> c[i].yy;
  73. }
  74. for(int i = 0;i < m;i++){
  75. int x, y, s;
  76. cin >> x >> y >> s;
  77. g[x].push_back({y, s});
  78. g[y].push_back({x, s});
  79. }
  80. djk(a, 0);
  81. djk(b, 1);
  82. ll ans = 1e15;
  83. for(int i = 1;i <= k;i++){
  84. ans = min(ans, d[c[i].xx][0] + d[c[i].xx][1] + c[i].yy);
  85. }
  86. cout << ans;
  87. rr;
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement