Advertisement
Guest User

Untitled

a guest
Jan 25th, 2015
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.83 KB | None | 0 0
  1. #include "cstdio"
  2. #include "algorithm"
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     freopen("cowroute.in" , "r" , stdin ) ;
  9.     freopen("cowroute.out" , "w" , stdout ) ;
  10.     int minim = 1 << 30 ;
  11.     int a , b , n ;
  12.     scanf ( "%d%d%d" , &a , &b , &n ) ;
  13.     for ( int i = 1 ; i <= n ; ++ i )
  14.     {
  15.         int cost , nr ;
  16.         scanf( "%d%d" , & cost , &nr ) ;
  17.         int ok1 = 0 , ok2 = 0 ;
  18.         for ( int j = 1 ; j <= nr ; ++ j )
  19.         {
  20.             int x ;
  21.             scanf ( "%d" , & x ) ;
  22.             if ( x == a )
  23.                 ok1 = j ;
  24.             if ( x == b )
  25.                 ok2 = j ;
  26.         }
  27.         if ( ok1 and ok2 and ok1 < ok2 )
  28.             minim = min ( cost , minim ) ;
  29.     }
  30.     if ( minim == 1 << 30 )
  31.         printf ( "-1\n" ) ;
  32.     else printf ( "%d\n" , minim ) ;
  33.     return 0;
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement