MAGCARI

Speed Up

Nov 21st, 2022
851
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.73 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. using ll = long long;
  4. struct A{
  5.     int nextNode,weEdge;
  6. };
  7. vector<A> g[80800];
  8. struct B{
  9.     ll currNode,sumTime,drink,last,divisor;
  10.     bool operator<(const B&o)const{
  11.         return sumTime>o.sumTime;
  12.     }
  13. };
  14. priority_queue<B> heap;
  15. ll t[80800][12];
  16. int markdrink[80800];
  17. int main(){
  18.     cin.tie(0) -> sync_with_stdio(0);
  19.     int n,l,m,q,u,v,w;
  20.     cin>>n>>m>>l>>q;
  21.     for(int i=0;i<m;i++){
  22.         cin>>u>>v>>w;
  23.         g[u].push_back({v,w});
  24.     }
  25.     int mm;
  26.     for(int i=0;i<l;i++){
  27.         cin>>mm;
  28.         markdrink[mm]=1;
  29.     }
  30.     for(int i=0;i<80800;i++)
  31.         for(int j=0;j<12;j++)
  32.             t[i][j] = 1e18;
  33.     heap.push({1,0,0,-1,1});
  34.     t[1][0]=0;
  35.     ll mn=1e18;
  36.     while(!heap.empty()){
  37.         B now = heap.top();
  38.         heap.pop();
  39.         // printf("%lld %lld %lld\n",now.currNode,now.sumTime,now.drink);
  40.         if(now.currNode==n){
  41.             cout << now.sumTime << '\n';
  42.             return 0;
  43.         }
  44.         for(auto x:g[now.currNode]){
  45.             if(t[x.nextNode][now.drink] > now.sumTime + x.weEdge/now.divisor){
  46.                 t[x.nextNode][now.drink] = now.sumTime + x.weEdge/now.divisor;
  47.                 heap.push({x.nextNode,t[x.nextNode][now.drink],now.drink,now.last,now.divisor});
  48.             }
  49.             if(now.last != now.currNode && markdrink[now.currNode] && now.drink<q && t[x.nextNode][now.drink+1] > now.sumTime + (x.weEdge/(now.divisor*2))){
  50.                 t[x.nextNode][now.drink+1] = now.sumTime + (x.weEdge/(now.divisor*2));
  51.                 heap.push({x.nextNode,t[x.nextNode][now.drink+1],now.drink+1,now.currNode,now.divisor*2});
  52.             }
  53.         }
  54.     }
  55.     return 0;
  56. }
  57. /*
  58. 9 9 1 1
  59. 1 2 256
  60. 2 3 256
  61. 3 4 256
  62. 4 9 256
  63. 1 5 256
  64. 5 6 256
  65. 6 7 256
  66. 7 8 256
  67. 8 9 256
  68. 5
  69.  
  70. */
Advertisement
Add Comment
Please, Sign In to add comment