| 比赛 | 
    20150408 | 
    评测结果 | 
    AWAAAAATWAAW | 
    | 题目名称 | 
    牛的路线 | 
    最终得分 | 
    66 | 
    | 用户昵称 | 
    cstdio | 
    运行时间 | 
    3.818 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.31 MiB  | 
    | 提交时间 | 
    2015-04-08 19:02:15 | 
显示代码纯文本
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
const int INF=0x7fffffff/2;
int main(){
	freopen("cowroute.in","r",stdin);
	freopen("cowroute.out","w",stdout);
	int A,B,N;
	int ans=INF;
	scanf("%d%d%d",&A,&B,&N);
	for(int i=1;i<=N;i++){
		int cost,n;
		scanf("%d%d",&cost,&n);
		int x;
		bool flag=false;
		for(int j=1;j<=n;j++){
			scanf("%d",&x);
			if(x==A){
				flag=true;
			}
			if(x==B&&flag){
				ans=min(ans,cost);
				break;
			}
		}
	}
	if(ans==INF) ans=-1;
	printf("%d\n",ans);
	return 0;
}