比赛 20150408 评测结果 AAAAAAAAAAAA
题目名称 牛的路线 最终得分 100
用户昵称 Asm.Def 运行时间 0.074 s
代码语言 C++ 内存使用 0.27 MiB
提交时间 2015-04-08 19:09:19
显示代码纯文本
/***********************************************************************/
/**********************By Asm.Def-Wu Jiaxin*****************************/
/***********************************************************************/
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cctype>
#include <algorithm>
using namespace std;
#define SetFile(x) ( freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout) );
#define getc() getchar() 
template<class T>inline void getd(T &x){
	char ch = getc();bool neg = false;
	while(!isdigit(ch) && ch != '-')ch = getc();
	if(ch == '-')ch = getc(), neg = true;
	x = ch - '0';
	while(isdigit(ch = getc()))x = x * 10 - '0' + ch;
	if(neg)x = -x;
}
/***********************************************************************/
const int maxn = 10003;

inline void work(){
	int ans = 0x7fffffff, A, B, N, w, t, cnt;
	bool tmp;
	getd(A), getd(B), getd(N);
	while(N--){
		getd(w), getd(cnt);tmp = false;
		while(cnt--){
			getd(t);
			if(tmp && t == B)ans = min(ans, w);
			else if(t == A)tmp = true;
		}
	}
	printf("%d\n", ans == 0x7fffffff ? -1 : ans);
}

int main(){

#ifdef DEBUG
	freopen("test.txt", "r", stdin);
#elif !defined ONLINE_JUDGE
	SetFile(cowroute);
#endif

	work();

#ifdef DEBUG
	printf("\n%lf sec \n", (double)clock() / CLOCKS_PER_SEC);
#endif
	return 0;
}