Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "cstdio"
- #include "algorithm"
- using namespace std;
- int main()
- {
- freopen("cowroute.in" , "r" , stdin ) ;
- freopen("cowroute.out" , "w" , stdout ) ;
- int minim = 1 << 30 ;
- int a , b , n ;
- scanf ( "%d%d%d" , &a , &b , &n ) ;
- for ( int i = 1 ; i <= n ; ++ i )
- {
- int cost , nr ;
- scanf( "%d%d" , & cost , &nr ) ;
- int ok1 = 0 , ok2 = 0 ;
- for ( int j = 1 ; j <= nr ; ++ j )
- {
- int x ;
- scanf ( "%d" , & x ) ;
- if ( x == a )
- ok1 = j ;
- if ( x == b )
- ok2 = j ;
- }
- if ( ok1 and ok2 and ok1 < ok2 )
- minim = min ( cost , minim ) ;
- }
- if ( minim == 1 << 30 )
- printf ( "-1\n" ) ;
- else printf ( "%d\n" , minim ) ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement