Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <vector>
- #include <sstream>
- #include <algorithm>
- #include <fstream>
- #include <list>
- #include <bitset>
- #include <map>
- #include <istream>
- #include <stack>
- #include <sstream>
- #include <unordered_map>
- #include <set>
- #include <cmath>
- #include <iostream>
- #include <iomanip>
- #include <queue>
- #include <string>
- #define endl "\n"
- #define all(x) x.begin(),x.end()
- #define xx first
- #define yy second
- #define rr return 0
- #define pii pair<int,int>
- typedef long long ll;
- typedef long double ld;
- const int NMAX = 5005;
- const int MMAX = 100000 + 5;
- const int KMAX = 5005;
- const ll INF = 1e15;
- using namespace std;
- int n, m, k;
- int a, b;
- pair<ll, ll> c[KMAX];
- vector<pair<ll, ll>> g[NMAX];
- ll d[NMAX][2];
- void djk(int from, int ind){
- for(int i = 1;i <= n;i++){
- d[i][ind] = INF;
- }
- d[from][ind] = 0;
- set<pair<ll, ll>> st;
- st.insert({d[from][ind], from});
- while(!st.empty()){
- pair<ll, ll> v = *st.begin();
- st.erase(st.begin());
- for(int i = 0;i < g[v.yy].size();i++){
- ll to = g[v.yy][i].xx;
- ll w = g[v.yy][i].yy;
- if(d[to][ind] > (d[v.yy][ind] + w)){
- st.erase({d[to][ind], to});
- d[to][ind] = d[v.yy][ind] + w;
- st.insert({d[to][ind], to});
- }
- }
- }
- }
- signed main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- cout.tie(0);
- cin >> n >> m >> k;
- cin >> a >> b;
- for(int i = 1;i <= k;i++){
- cin >> c[i].xx >> c[i].yy;
- }
- for(int i = 0;i < m;i++){
- int x, y, s;
- cin >> x >> y >> s;
- g[x].push_back({y, s});
- g[y].push_back({x, s});
- }
- djk(a, 0);
- djk(b, 1);
- ll ans = 1e15;
- for(int i = 1;i <= k;i++){
- ans = min(ans, d[c[i].xx][0] + d[c[i].xx][1] + c[i].yy);
- }
- cout << ans;
- rr;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement