Advertisement
Guest User

Untitled

a guest
Aug 20th, 2014
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.14 KB | None | 0 0
  1. int main()
  2. {
  3.     get_input();
  4.  
  5.     d[1][1].cost = 0;
  6.     d[1][1].tel = 0;
  7.  
  8.  
  9.     to.planet = 1;
  10.     to.anc = 1;
  11.     to.cost = 0;
  12.     to.tel = 0;
  13.  
  14.  
  15.     q.insert( to );
  16.     while( !q.empty() )
  17.     {
  18.         now = *q.begin();
  19.         q.erase( q.begin() );
  20.  
  21.         for( i=0; i < g[ now.planet ][ now.anc ].size(); i++ )
  22.         {
  23.             P = g[ now.planet ][ now.anc ][i].planet;
  24.             C = g[ now.planet ][ now.anc ][i].cost;
  25.             A = g[ now.planet ][ now.anc ][i].anc;
  26.             T = g[ now.planet ][ now.anc ][i].tel;
  27.  
  28.             if( d[P][A].tel > now.tel+T || (d[P][A].tel == now.tel+T && d[P][A].cost > now.cost+C) )
  29.             {
  30.                 to.planet = P;
  31.                 to.anc = A;
  32.                 to.cost = d[P][A].cost;
  33.                 to.tel = d[P][A].tel;
  34.  
  35.                 q.erase( to );
  36.  
  37.                 d[P][A].cost = now.cost+C;
  38.                 d[P][A].tel  = now.tel+T;
  39.                 to.cost = d[P][A].cost;
  40.                 to.tel  = d[P][A].tel;
  41.  
  42.                 q.insert( to );
  43.             }
  44.         }
  45.     }
  46.  
  47.     printf( "%lld %lld", d[n][k].tel, d[n][k].cost );
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement