Advertisement
LZsolar

CUBE-228: Magic Pooh

May 14th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define inf 2e18
  4. typedef long long ll;
  5. typedef pair<ll,pair<ll,ll>> pii;
  6. ll n,m,k,t;
  7.  
  8. int main(){
  9.     scanf("%lld %lld %lld %lld",&n,&m,&k,&t);
  10.     vector<pair<ll,ll>> mp[n+1];
  11.     for(ll i=0;i<m;i++){
  12.         ll a,b,x;
  13.         scanf("%lld %lld %lld",&a,&b,&x);
  14.         mp[a].push_back({b,x});
  15.         mp[b].push_back({a,x});
  16.     }
  17.    
  18.     vector<vector<ll>> dist(n+1,vector<ll>(2,inf));
  19.     vector<vector<bool>> visited(n+1,vector<bool>(2,false));
  20.     priority_queue<pii,vector<pii>,greater<pii>> q;
  21.     dist[1][0]=0;
  22.     q.push({0,{0,1}});
  23.     bool find =false;
  24.     while(!q.empty()){
  25.         ll u=q.top().second.second,key=q.top().second.first;
  26.         q.pop();
  27.        
  28.         if(visited[u][key]){continue;}
  29.         visited[u][key]=true;
  30.        
  31.         if(u==n){
  32.             find = true;
  33.             break;
  34.         }
  35.        
  36.         for(auto x:mp[u]){
  37.             ll v=x.first,w=x.second;
  38.             if(dist[u][key]+w<dist[v][key]){
  39.                 dist[v][key]=dist[u][key]+w;
  40.                 q.push({dist[v][key],{key,v}});
  41.             }
  42.             if(key==0&&dist[u][0]+k<dist[v][1]){
  43.                 dist[v][1]=dist[u][0]+k;
  44.                 q.push({dist[v][1],{1,v}});
  45.             }
  46.         }
  47.     }
  48.     if(find&&(dist[n][1]<=t||dist[n][0]<=t)){
  49.         if(dist[n][1]<=dist[n][0]){printf("Happy Winnie the Pooh :3\n%lld",dist[n][1]);}
  50.         else{printf("Happy Winnie the Pooh :3\n%lld",dist[n][0]);}
  51.     }
  52.     else{printf("No Honey TT");}
  53.  
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement