MAGCARI

Taep Nitrous

Nov 14th, 2022 (edited)
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.34 KB | None | 0 0
  1. /*
  2.     Task    : _example
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 14 November 2022 [20:46]
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. struct A{
  10.     int v,w,state;
  11.     bool operator < (const A&o) const{
  12.         return w>o.w;
  13.     }
  14. };
  15. priority_queue<A > heap;
  16. int dis[5010][110];
  17. struct B{
  18.     int nextNode,edgeWeight;
  19. };
  20. vector<B > g[5010];
  21. int main(){
  22.     cin.tie(0)->sync_with_stdio(0);
  23.     cin.exceptions(cin.failbit);
  24.     int n,m,k;
  25.     cin >> n >> m >> k;
  26.     for(int i=1;i<=m;i++){
  27.         int u,v,w;
  28.         cin >> u >> v >> w;
  29.         g[u].push_back({v,w});
  30.         g[v].push_back({u,w});
  31.     }
  32.     for(int i=1;i<=n;i++){
  33.         for(int j=0;j<=k;j++){
  34.             dis[i][j] = 1e9;
  35.         }
  36.     }
  37.     dis[1][0] = 0;
  38.     heap.push({1,0,0});
  39.     while(!heap.empty()){
  40.         A now = heap.top();
  41.         heap.pop();
  42.         for(auto x:g[now.v]){
  43.             //special
  44.             if(now.state+1<=k && dis[x.nextNode][now.state+1] > now.w + x.edgeWeight/2){
  45.                 dis[x.nextNode][now.state+1] = now.w + x.edgeWeight/2;
  46.                 heap.push({x.nextNode,now.w+x.edgeWeight/2,now.state+1});
  47.             }
  48.  
  49.             //normal
  50.             if(dis[x.nextNode][now.state] > now.w + x.edgeWeight){
  51.                 dis[x.nextNode][now.state] = now.w + x.edgeWeight;
  52.                 heap.push({x.nextNode,now.w+x.edgeWeight,now.state});
  53.             }
  54.         }
  55.     }
  56.     int mn = 1e9;
  57.     for(int j=0;j<=k;j++)
  58.         mn = min(mn,dis[n][j]);
  59.     cout << dis[n][0] << '\n' << mn << '\n' << dis[n][0]-mn << '\n';
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment