daily pastebin goal
25%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2. #define PI 2*asin(1)
  3. #define FOR(i,n) for(long long i = 0; i < n;i++)
  4. using namespace std;
  5. long long n,m,s,t;
  6. vector <long long>res;
  7. vector<vector<pair<long long,long long>>>rast(100001);
  8. void go(long long v){
  9.     for(long long i = 0; i < rast[v].size(); i++){
  10.         res[rast[v][i].first] = min(res[rast[v][i].first], res[v]+rast[v][i].second);
  11.         go(rast[v][i].first);
  12.     }
  13. }
  14. int main()
  15. {
  16.     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  17.  
  18.     cin >> n >> m >> s >> t; s--;t--;
  19.     FOR(i,n) res.push_back(INT_MAX);
  20.     res[s] = 0;
  21.     FOR(i,m){
  22.         long long x,y,z;cin >> x >> y >> z; x--;y--;
  23.         rast[x].push_back({y,z});
  24.     }
  25.     go(s);
  26.     long long y = res[t];
  27.     if(y<INT_MAX)cout << res[t];
  28.     else cout << "Unreachable";
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top