YEZAELP

CUBE-185: osu! mapping

Jun 7th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. const long long INF = 1e18;
  4. using pii=pair<long long,pair<int,int>>;
  5.  
  6. int main(){
  7.  
  8.     int n,m,x,y;
  9.     int t;
  10.     scanf("%d%d%d%d%d",&n,&m,&t,&x,&y);
  11.     vector <pair<int,int>> g[n+10];
  12.     vector <vector<long long>> dis(n+10,vector <long long>(10,INF) );
  13.     vector <vector<bool>> visited(n+10,vector <bool>(10,false) );
  14.  
  15.     for(int i=1;i<=m;i++){
  16.         int u,v,w;
  17.         scanf("%d%d%d",&u,&v,&w);
  18.         g[u].push_back({v,w});
  19.     }
  20.  
  21.     priority_queue <pii,vector<pii>,greater<pii>> pq;
  22.     dis[x][1]=0;
  23.     pq.push({dis[x][1],{x,1}});
  24.     while(pq.size()>0){
  25.         int u,c;
  26.         long long d;
  27.         d=pq.top().first;
  28.         u=pq.top().second.first;
  29.         c=pq.top().second.second;
  30.         pq.pop();
  31.  
  32.         if(u==y && c==t){
  33.             printf("%lld",d);
  34.             return 0;
  35.         }
  36.  
  37.         for(auto vw:g[u]){
  38.             int v,w,cv;
  39.             v=vw.first;
  40.             w=vw.second;
  41.             cv=c+1;
  42.             if(cv==t+1) cv=1;
  43.             if(dis[u][c%(t+1)]+w<dis[v][cv%(t+1)]){
  44.                 dis[v][cv%(t+1)]=dis[u][c%(t+1)]+w;
  45.                 pq.push({dis[v][cv%(t+1)],{v,cv%(t+1)}});
  46.             }
  47.         }
  48.  
  49.     }
  50.  
  51.     printf("-1");
  52.  
  53.  
  54.     return 0;
  55. }
Add Comment
Please, Sign In to add comment