| 比赛 | 
    20150408 | 
    评测结果 | 
    AAAAAAAAAAAA | 
    | 题目名称 | 
    牛的路线 | 
    最终得分 | 
    100 | 
    | 用户昵称 | 
    TA | 
    运行时间 | 
    0.113 s  | 
    | 代码语言 | 
    C++ | 
    内存使用 | 
    0.31 MiB  | 
    | 提交时间 | 
    2015-04-08 19:16:21 | 
显示代码纯文本
#include<cstdio>
#include<iostream>
using namespace std;
int main(){
	freopen("cowroute.in","r",stdin);
	freopen("cowroute.out","w",stdout);
	int A,B,N;
	scanf("%d%d%d",&A,&B,&N);
	int ans=0x7fffffff,cost,sum,i,city;
	bool flagA,flagB;
	for(i=0;i<N;++i){
		scanf("%d%d",&cost,&sum);
		flagA=flagB=0;
		while(sum--){
			scanf("%d",&city);
			if(flagA){
				if(city==B)flagB=1;
			}
			else if(city==A)flagA=1;
		}
		if(flagB)ans=min(ans,cost);
	}
	if(ans>1E8)printf("-1\n");
	else printf("%d\n",ans);
}