Share Pastebin
Guest
Public paste!

Untitled

By: a guest | Mar 21st, 2010 | Syntax: C++ | Size: 1.36 KB | Hits: 79 | Expires: Never
Copy text to clipboard
  1. #include <cstdio>
  2. #include <algorithm>
  3. #include <cstring>
  4.  
  5. using namespace std;
  6.  
  7. typedef long long llint;
  8.  
  9. const llint inf = 100000000000000000LL;
  10.  
  11. int n;
  12. struct matrix {
  13.   llint a[102][102];
  14.   matrix() {};
  15.   friend matrix operator * ( const matrix &a, const matrix &b ) {
  16.     matrix r;
  17.     for( int i = 0; i < n; ++i )
  18.       for( int j = 0; j < n; ++j ) {
  19.         r.a[i][j] = inf;
  20.         for( int k = 0; k < n; ++k )
  21.           r.a[i][j] = min( r.a[i][j], a.a[i][k]+b.a[k][j] );
  22.       }
  23.     return r;
  24.   }
  25. };
  26.  
  27. int v[1002];
  28. matrix a[64];
  29.  
  30. int main( void ) {
  31.   llint t;
  32.   scanf( "%d %lld", &n, &t );
  33.   for( int i = 0; i < n; ++i ) {
  34.     int k, y, x;
  35.     scanf( "%d %d", &k, &y );
  36.    
  37.     for( int j = 0; j < n; ++j )
  38.       a[0].a[i][j] = inf;
  39.  
  40.     for( int j = 0; j < k; ++j )
  41.       scanf( "%d", v+j );
  42.     for( int j = 0; j < k; ++j ) {
  43.       scanf( "%d", &x ); --v[j];
  44.       a[0].a[i][ v[j] ] = min( a[0].a[i][ v[j] ], llint( x+y ) );
  45.     }
  46.   }
  47.  
  48.   int s = 0;
  49.   while( (1LL<<s) < t ) a[s+1] = a[s]*a[s], s++;
  50.  
  51.   matrix w;
  52.   memset( w.a, 0, sizeof( w.a ) );
  53.  
  54.   llint ans = 0;
  55.   for( int i = s; i >= 0; --i ) {
  56.     matrix q = w;
  57.     q = q*a[i];
  58.    
  59.     llint f = inf;
  60.     for( int j = 0; j < n; ++j )
  61.       for( int k = 0; k < n; ++k )
  62.         f = min( f, q.a[j][k] );
  63.  
  64.     if( f <= t ) w = q, ans += (1LL<<i);
  65.   }
  66.  
  67.   printf( "%lld\n", ans );
  68.   return 0;
  69. }